IdentityHashMap & natStackTrace
Tom Tromey
tromey@redhat.com
Sat Nov 27 01:55:00 GMT 2004
>>>>> "Ranjit" == Ranjit Mathew <rmathew@gmail.com> writes:
Ranjit> This was introduced almost two years ago in a merge from
Ranjit> Classpath:
Yeah, there was a wave of changing "* 2" to "<< 1". As Bryce and
Andrew point out, this is a non-optimization.
Ranjit> // This isn't necessarily prime, but it is an odd number of key/value
Ranjit> // slots, which has a higher probability of fewer collisions.
Ranjit> - table = new Object[old.length * 2 + 2];
Ranjit> + table = new Object[old.length << 1 + 2];
Ranjit> I think this is surely a bug - the comment above this line
Ranjit> didn't hold earlier and doesn't hold now - we still have
Ranjit> an even number of slots.
The comment is correct, just a little confusing. The missing piece of
information is that the table stores the key at index N and the value
at index N+1. So, adding 2 to the length of the underlying array
means that you're adding 1 to the size of the map, hence it is odd (as
the .length is always even).
Tom
More information about the Java
mailing list