RFR: [6904367]: (coll) IdentityHashMap is resized before exceeding the expected maximum size (original) (raw)

Jeff Hain jeffhain at rocketmail.com
Sun Jul 6 11:13:26 UTC 2014


So, I reverted this change to the original code, but added a single check of the current table size before doing any modifications to the map. This is to address the issue #4, and this doesn't seem to introduce any significant penalty.

Would you please help review the updated webrev: http://cr.openjdk.java.net/~igerasim/6904367/3/webrev/ Sincerely yours, Ivan

It's possible to avoid the capacity test for the general case: put {     ...while loop...

    if (size < threshold) {         modCount++;         tab[i] = k;         tab[i + 1] = value;         ++size;     } else {         putAndResize(k, value, i);     }     return null; } private void putAndResize(Object k, Object value, int i) {     if (size == MAXIMUM_CAPACITY - 1)         throw new IllegalStateException("Capacity exhausted.");     modCount++;     Object[] tab = table;     tab[i] = k;     tab[i + 1] = value;     ++size;     resize(tab.length); // len == 2 * current capacity. }

It seems faster more often than not, but it adds more (and copied) code: not sure it's worth it.

-Jeff



More information about the core-libs-dev mailing list