Changeset 2769 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Nov 19, 2002, 5:23:02 PM (23 years ago)
Author:
darin
Message:
  • another step towards atomic identifiers; storing hash in the string rep. gives about a 1.5% speedup in the JavaScript iBench
  • kjs/ustring.h: Add a hash field to UString::Rep.
  • kjs/ustring.cpp: (UString::Rep::create): Set hash to uninitialized value. (UString::Rep::destroy): Do the deleting in her, and call Identifier if needed. (UString::Rep::computeHash): Added. (UString::append): Set hash to 0 when modifying the string in place. (UString::operator=): Ditto.
  • kjs/property_map.cpp: Use the hash from UString.
  • kjs/identifier.h: Added aboutToDestroyUStringRep.
  • kjs/identifier.cpp: (Identifier::aboutToDestroyUStringRep): Added.
Location:
trunk/JavaScriptCore/kjs
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/identifier.cpp

    r2766 r2769  
    3131}
    3232
     33void Identifier::aboutToDestroyUStringRep(UString::Rep *)
     34{
     35}
     36
    3337} // namespace KJS
  • trunk/JavaScriptCore/kjs/identifier.h

    r2766 r2769  
    5858        friend bool operator==(const Identifier &, const char *);
    5959   
     60        static void aboutToDestroyUStringRep(UString::Rep *);
     61
    6062    private:
    6163        UString _ustring;
  • trunk/JavaScriptCore/kjs/property_map.cpp

    r2766 r2769  
    6565}
    6666
    67 int PropertyMap::hash(const UString::Rep *s) const
    68 {
    69     int h = 0;
    70     int length = s->len;
    71     int prefixLength = length < 8 ? length : 8;
    72     for (int i = 0; i < prefixLength; i++)
    73         h = (127 * h + s->dat[i].unicode()) & _tableSizeHashMask;
    74     int suffixPosition = length < 16 ? 8 : length - 8;
    75     for (int i = suffixPosition; i < length; i++)
    76         h = (127 * h + s->dat[i].unicode()) & _tableSizeHashMask;
    77     return h;
     67inline int PropertyMap::hash(const UString::Rep *s) const
     68{
     69    return s->hash() & _tableSizeHashMask;
    7870}
    7971
  • trunk/JavaScriptCore/kjs/ustring.cpp

    r2762 r2769  
    3737#include "ustring.h"
    3838#include "operations.h"
     39#include "identifier.h"
    3940#include <math.h>
    4041
     
    115116
    116117UChar UChar::null((char)0);
    117 UString::Rep UString::Rep::null = { 0, 0, 0, 1 };
    118 UString::Rep UString::Rep::empty = { 0, 0, 0, 1 };
     118UString::Rep UString::Rep::null = { 0, 0, 0, 1, 1 };
     119UString::Rep UString::Rep::empty = { 0, 0, 0, 1, 1 };
    119120UString UString::null;
    120121const int normalStatBufferSize = 4096;
     
    163164  r->capacity = l;
    164165  r->rc = 1;
     166  r->_hash = 0;
    165167
    166168  return r;
     169}
     170
     171void UString::Rep::destroy()
     172{
     173  if (capacity == capacityForIdentifier)
     174    Identifier::aboutToDestroyUStringRep(this);
     175  delete [] dat;
     176  delete this;
     177}
     178
     179void UString::Rep::computeHash() const
     180{
     181    int length = len;
     182    int prefixLength = length < 8 ? length : 8;
     183    int suffixPosition = length < 16 ? 8 : length - 8;
     184
     185    unsigned h = length;
     186    for (int i = 0; i < prefixLength; i++)
     187        h = 127 * h + dat[i].unicode();
     188    for (int i = suffixPosition; i < length; i++)
     189        h = 127 * h + dat[i].unicode();
     190    if (h == 0)
     191        h = 0x80000000;
     192    _hash = h;
    167193}
    168194
     
    329355    memcpy(rep->dat+l, t.data(), tLen * sizeof(UChar));
    330356    rep->len = newLen;
     357    rep->_hash = 0;
    331358    return *this;
    332359  }
     
    389416  int l = c ? strlen(c) : 0;
    390417  UChar *d;
    391   if (rep->rc == 1 && l < rep->capacity) {
     418  if (rep->rc == 1 && l <= rep->capacity) {
    392419    d = rep->dat;
     420    rep->_hash = 0;
    393421  } else {
    394422    release();
  • trunk/JavaScriptCore/kjs/ustring.h

    r2749 r2769  
    200200    friend bool operator==(const UString&, const UString&);
    201201    friend class UCharReference;
     202    friend class Identifier;
    202203    friend class PropertyMap;
    203204    friend class PropertyMapHashTableEntry;
     205
    204206    /**
    205207     * @internal
     
    208210      friend class UString;
    209211      friend bool operator==(const UString&, const UString&);
     212     
    210213      static Rep *create(UChar *d, int l);
    211       inline UChar *data() const { return dat; }
    212       inline int size() const { return len; }
    213 
    214       inline void ref() { rc++; }
    215       inline void deref() {
    216         if (--rc == 0) {
    217           delete [] dat;
    218           delete this;
    219         }
    220       }
     214      void destroy();
     215     
     216      UChar *data() const { return dat; }
     217      int size() const { return len; }
     218     
     219      int hash() const { if (_hash == 0) computeHash(); return _hash; }
     220      void computeHash() const;
     221
     222      void ref() { ++rc; }
     223      void deref() { if (--rc == 0) destroy(); }
    221224
    222225      UChar *dat;
     
    224227      int capacity;
    225228      int rc;
     229      mutable int _hash;
     230     
     231      enum { capacityForIdentifier = 0x10000000 };
     232     
    226233      static Rep null;
    227234      static Rep empty;
Note: See TracChangeset for help on using the changeset viewer.