IdentityHashMap & natStackTrace
Bryce McKinlay
mckinlay@redhat.com
Fri Nov 26 09:19:00 GMT 2004
Ranjit Mathew wrote:
>As Chris points, due to operator precedence weirdness this
>becomes a left shift by 3 or multiplication by 23, in line
>with what you observed.
>
>This was introduced almost two years ago in a merge from
>Classpath:
>
>http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/util/IdentityHashMap.java.diff?r1=1.8&r2=1.9&only_with_tag=MAIN
>
>Relevant change:
>
> // This isn't necessarily prime, but it is an odd number of key/value
> // slots, which has a higher probability of fewer collisions.
>- table = new Object[old.length * 2 + 2];
>+ table = new Object[old.length << 1 + 2];
>
>
I'd like to make a plea to Classpath developers not to make this kind of
change in the future. Not only does the new code introduce a bug, it is
also more difficult to read, and it won't make any performance
difference on any modern compiler. Its trivial for optimizers to
substitute constant multiply's to left-shift operations, so please let
the compiler take care of it!
Regards
Bryce
More information about the Java
mailing list