Changeset 2769 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp


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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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();
Note: See TracChangeset for help on using the changeset viewer.