Ignore:
Timestamp:
Oct 31, 2007, 1:22:12 AM (18 years ago)
Author:
mjs
Message:

Reviewed by ChangeLog.


  • get rid of integer divide in PropertyMap and HashTable for 1% SunSpider speedup


Integer divide sucks. Fortunately, a bunch of shifts and XORs
biased towards the high bits is sufficient to provide a good
double hash. Besides the SunSpider win, I used the dump statistics
mode for both to verify that collisions did not increase and that
the longest collision chain is not any longer.

  • kjs/property_map.cpp: (KJS::doubleHash): (KJS::PropertyMap::get): (KJS::PropertyMap::getLocation): (KJS::PropertyMap::put): (KJS::PropertyMap::insert): (KJS::PropertyMap::remove): (KJS::PropertyMap::checkConsistency):
  • wtf/HashTable.h: (WTF::doubleHash): (WTF::::lookup): (WTF::::lookupForWriting): (WTF::::fullLookupForWriting): (WTF::::add):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/HashTable.h

    r27221 r27301  
    398398    }
    399399
     400    static inline unsigned doubleHash(unsigned key)
     401    {
     402        key = ~key + (key >> 23);
     403        key ^= (key << 12);
     404        key ^= (key >> 7);
     405        key ^= (key << 2);
     406        key ^= (key >> 20);
     407        return key;
     408    }
     409
    400410    template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
    401411    template<typename T, typename HashTranslator>
     
    443453#endif
    444454            if (k == 0)
    445                 k = 1 | (h % sizeMask);
     455                k = 1 | doubleHash(h);
    446456            i = (i + k) & sizeMask;
    447457        }
     
    500510#endif
    501511            if (k == 0)
    502                 k = 1 | (h % sizeMask);
     512                k = 1 | doubleHash(h);
    503513            i = (i + k) & sizeMask;
    504514        }
     
    557567#endif
    558568            if (k == 0)
    559                 k = 1 | (h % sizeMask);
     569                k = 1 | doubleHash(h);
    560570            i = (i + k) & sizeMask;
    561571        }
     
    622632#endif
    623633            if (k == 0)
    624                 k = 1 | (h % sizeMask);
     634                k = 1 | doubleHash(h);
    625635            i = (i + k) & sizeMask;
    626636        }
Note: See TracChangeset for help on using the changeset viewer.