Changeset 12971 for trunk/abcl/src/org


Ignore:
Timestamp:
10/10/10 15:48:48 (11 years ago)
Author:
ehuelsmann
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/HashTable.java

    r12970 r12971  
    250250    protected HashEntry getEntry(LispObject key) {
    251251        HashEntry[] b = buckets;
    252         HashEntry e = b[comparator.hash(key) & (b.length - 1)];
     252        int hash = comparator.hash(key);
     253        HashEntry e = b[hash & (b.length - 1)];
    253254        while (e != null) {
    254             if (comparator.keysEqual(key, e.key)) {
     255            if (hash == e.hash &&
     256                    (key == e.key || comparator.keysEqual(key, e.key))) {
    255257                return e;
    256258            }
     
    288290                }
    289291
    290                 int index = comparator.hash(key) & (buckets.length - 1);
    291                 buckets[index] = new HashEntry(key, value, buckets[index]);
     292                int hash = comparator.hash(key);
     293                int index = hash & (buckets.length - 1);
     294                buckets[index] = new HashEntry(key, hash, value, buckets[index]);
    292295            }
    293296        } finally {
     
    334337                while (e != null) {
    335338                    final int index = comparator.hash(e.key) & mask;
    336                     newBuckets[index] = new HashEntry(e.key, e.value, newBuckets[index]);
     339                    newBuckets[index] = new HashEntry(e.key, e.hash, e.value,
     340                            newBuckets[index]);
    337341                    e = e.next;
    338342                }
     
    437441
    438442        LispObject key;
     443        int hash;
    439444        volatile LispObject value;
    440445        HashEntry next;
    441446
    442         HashEntry(LispObject key, LispObject value, HashEntry next) {
     447        HashEntry(LispObject key, int hash, LispObject value, HashEntry next) {
    443448            this.key = key;
     449            this.hash = hash;
    444450            this.value = value;
    445451            this.next = next;
Note: See TracChangeset for help on using the changeset viewer.