Changeset 27127 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Oct 26, 2007, 3:45:34 PM (18 years ago)
Author:
ggaren
Message:

Reviewed by Maciej Stachowiak.


Tweaked property maps to remove 2 branches. 2.5% speedup on SunSpider.

  • kjs/property_map.cpp: Use a special no branch accessor to the UString's hash value. Also, return immediately instead of branching to the end of the loop if the value is not found. (KJS::PropertyMap::get): (KJS::PropertyMap::getLocation): (KJS::PropertyMap::put): (KJS::PropertyMap::insert): (KJS::PropertyMap::remove): (KJS::PropertyMap::checkConsistency):
  • kjs/ustring.h: (KJS::UString::Rep::computedHash): Special no branch accessor to the UString's hash value. Used when the caller knows that the hash value has already been computed. (For example, if the caller got the UString from an Identifier.)
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r27126 r27127  
     12007-10-26  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Maciej Stachowiak.
     4       
     5        Tweaked property maps to remove 2 branches. 2.5% speedup on SunSpider.
     6
     7        * kjs/property_map.cpp: Use a special no branch accessor to the UString's
     8        hash value. Also, return immediately instead of branching to the end
     9        of the loop if the value is not found.
     10        (KJS::PropertyMap::get):
     11        (KJS::PropertyMap::getLocation):
     12        (KJS::PropertyMap::put):
     13        (KJS::PropertyMap::insert):
     14        (KJS::PropertyMap::remove):
     15        (KJS::PropertyMap::checkConsistency):
     16
     17        * kjs/ustring.h:
     18        (KJS::UString::Rep::computedHash): Special no branch accessor to the
     19        UString's hash value. Used when the caller knows that the hash value
     20        has already been computed. (For example, if the caller got the UString
     21        from an Identifier.)
     22
    1232007-10-26  Geoffrey Garen  <[email protected]>
    224
  • trunk/JavaScriptCore/kjs/property_map.cpp

    r26958 r27127  
    3838#define USE_SINGLE_ENTRY 1
    3939
    40 // 2/28/2006 ggaren: super accurate JS iBench says that USE_SINGLE_ENTRY is a
     40// 2/28/2006 ggaren: command-line JS iBench says that USE_SINGLE_ENTRY is a
    4141// 3.2% performance boost.
    4242
     
    176176    }
    177177   
    178     unsigned h = rep->hash();
     178    unsigned h = rep->computedHash();
    179179    int sizeMask = m_u.table->sizeMask;
    180180    Entry *entries = m_u.table->entries;
     
    185185    numCollisions += entries[i].key && entries[i].key != rep;
    186186#endif
    187     while (UString::Rep *key = entries[i].key) {
     187    while (1) {
     188        UString::Rep* key = entries[i].key;
     189
     190        if (!key)
     191            return 0;
     192
    188193        if (rep == key) {
    189194            attributes = entries[i].attributes;
    190195            return entries[i].value;
    191196        }
     197       
    192198        if (k == 0)
    193199            k = 1 | (h % sizeMask);
     
    197203#endif
    198204    }
    199     return 0;
    200205}
    201206
     
    215220    }
    216221   
    217     unsigned h = rep->hash();
     222    unsigned h = rep->computedHash();
    218223    int sizeMask = m_u.table->sizeMask;
    219224    Entry *entries = m_u.table->entries;
     
    224229    numCollisions += entries[i].key && entries[i].key != rep;
    225230#endif
    226     while (UString::Rep *key = entries[i].key) {
     231    while (1) {
     232        UString::Rep* key = entries[i].key;
     233
     234        if (!key)
     235            return 0;
     236
    227237        if (rep == key)
    228238            return entries[i].value;
     239       
    229240        if (k == 0)
    230241            k = 1 | (h % sizeMask);
     
    234245#endif
    235246    }
    236     return 0;
    237247}
    238248
     
    252262    }
    253263   
    254     unsigned h = rep->hash();
     264    unsigned h = rep->computedHash();
    255265    int sizeMask = m_u.table->sizeMask;
    256266    Entry *entries = m_u.table->entries;
     
    261271    numCollisions += entries[i].key && entries[i].key != rep;
    262272#endif
    263     while (UString::Rep *key = entries[i].key) {
     273    while (1) {
     274        UString::Rep* key = entries[i].key;
     275
     276        if (!key)
     277            return 0;
     278
    264279        if (rep == key)
    265280            return &entries[i].value;
     281       
    266282        if (k == 0)
    267283            k = 1 | (h % sizeMask);
     
    271287#endif
    272288    }
    273     return 0;
    274289}
    275290
     
    331346        expand();
    332347   
    333     unsigned h = rep->hash();
     348    unsigned h = rep->computedHash();
    334349    int sizeMask = m_u.table->sizeMask;
    335350    Entry *entries = m_u.table->entries;
     
    385400    ASSERT(m_u.table);
    386401
    387     unsigned h = key->hash();
     402    unsigned h = key->computedHash();
    388403    int sizeMask = m_u.table->sizeMask;
    389404    Entry *entries = m_u.table->entries;
     
    512527
    513528    // Find the thing to remove.
    514     unsigned h = rep->hash();
     529    unsigned h = rep->computedHash();
    515530    int sizeMask = m_u.table->sizeMask;
    516531    Entry *entries = m_u.table->entries;
     
    729744            continue;
    730745        }
    731         unsigned h = rep->hash();
     746        unsigned h = rep->computedHash();
    732747        int i = h & m_u.table->sizeMask;
    733748        int k = 0;
  • trunk/JavaScriptCore/kjs/ustring.h

    r25321 r27127  
    148148     
    149149      unsigned hash() const { if (_hash == 0) _hash = computeHash(data(), len); return _hash; }
     150      unsigned computedHash() const { ASSERT(_hash); return _hash; } // fast path for Identifiers
     151
    150152      static unsigned computeHash(const UChar *, int length);
    151153      static unsigned computeHash(const char *);
Note: See TracChangeset for help on using the changeset viewer.