4 ms·
Is this a correct summary: we memoized the hashCode() function?
by koliber 1y ago
Is this a correct summary: we memoized the hashCode() function?
- matsemann 1y agoNot only that. By making it guaranteed constant after first invocation, they can fold the constant and basically avoid the map lookup in runtime and instead do it compile-time. In practice avoiding the map entirely.
- nimrody 1y agoNo. String.hashCode() was already memoized. So after the first call to hashCode(), future calls just retrieved the data from the hash field of the string object. This optimization is about avoiding even calling the method because the jvm knows that the value returned will be the same.