src/share/classes/java/util/Hashtable.java
Print this page
rev 5440 : 7173919: Minor optimization of hashing methods
Summary: several minor optimizations to hashing methods used by hash map classes
Reviewed-by: duke
@@ -192,24 +192,22 @@
* hash code of keys to make hash collisions harder to find.
*/
transient final int hashSeed = sun.misc.Hashing.randomHashSeed(this);
private int hash(Object k) {
- int h = hashSeed;
-
if (k instanceof String) {
return ((String)k).hash32();
- } else {
- h ^= k.hashCode();
+ }
+
+ int h = hashSeed ^ k.hashCode();
// This function ensures that hashCodes that differ only by
// constant multiples at each bit position have a bounded
// number of collisions (approximately 8 at default load factor).
h ^= (h >>> 20) ^ (h >>> 12);
return h ^ (h >>> 7) ^ (h >>> 4);
}
- }
/**
* Constructs a new, empty hashtable with the specified initial
* capacity and the specified load factor.
*
@@ -1013,11 +1011,11 @@
/**
* Hashtable bucket collision list entry
*/
private static class Entry<K,V> implements Map.Entry<K,V> {
final int hash;
- K key;
+ final K key;
V value;
Entry<K,V> next;
protected Entry(int hash, K key, V value, Entry<K,V> next) {
this.hash = hash;