[armedbear-cvs] r12971 - trunk/abcl/src/org/armedbear/lisp

Erik Huelsmann ehuelsmann at common-lisp.net
Sun Oct 10 15:48:49 UTC 2010


Author: ehuelsmann
Date: Sun Oct 10 11:48:48 2010
New Revision: 12971

Log:
Small performance improvement for non-EQ hash tables;
don't use comparator when key and HashEntry.key are the
same object.  Along the same lines, compare the keys *only*
if the hash values are equal.

Modified:
   trunk/abcl/src/org/armedbear/lisp/HashTable.java

Modified: trunk/abcl/src/org/armedbear/lisp/HashTable.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/HashTable.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/HashTable.java	Sun Oct 10 11:48:48 2010
@@ -249,9 +249,11 @@
 
     protected HashEntry getEntry(LispObject key) {
         HashEntry[] b = buckets;
-        HashEntry e = b[comparator.hash(key) & (b.length - 1)];
+        int hash = comparator.hash(key);
+        HashEntry e = b[hash & (b.length - 1)];
         while (e != null) {
-            if (comparator.keysEqual(key, e.key)) {
+            if (hash == e.hash &&
+                    (key == e.key || comparator.keysEqual(key, e.key))) {
                 return e;
             }
             e = e.next;
@@ -287,8 +289,9 @@
                     rehash();
                 }
 
-                int index = comparator.hash(key) & (buckets.length - 1);
-                buckets[index] = new HashEntry(key, value, buckets[index]);
+                int hash = comparator.hash(key);
+                int index = hash & (buckets.length - 1);
+                buckets[index] = new HashEntry(key, hash, value, buckets[index]);
             }
         } finally {
             lock.unlock();
@@ -333,7 +336,8 @@
                 HashEntry e = buckets[i];
                 while (e != null) {
                     final int index = comparator.hash(e.key) & mask;
-                    newBuckets[index] = new HashEntry(e.key, e.value, newBuckets[index]);
+                    newBuckets[index] = new HashEntry(e.key, e.hash, e.value,
+                            newBuckets[index]);
                     e = e.next;
                 }
             }
@@ -436,11 +440,13 @@
     protected static class HashEntry {
 
         LispObject key;
+        int hash;
         volatile LispObject value;
         HashEntry next;
 
-        HashEntry(LispObject key, LispObject value, HashEntry next) {
+        HashEntry(LispObject key, int hash, LispObject value, HashEntry next) {
             this.key = key;
+            this.hash = hash;
             this.value = value;
             this.next = next;
         }




More information about the armedbear-cvs mailing list