Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is this a correct summary: we memoized the hashCode() function?


No. 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.


Not 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: