This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: IdentityHashMap & natStackTrace


>>>>> "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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]