Changeset 2769 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Nov 19, 2002, 5:23:02 PM (23 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/identifier.cpp
r2766 r2769 31 31 } 32 32 33 void Identifier::aboutToDestroyUStringRep(UString::Rep *) 34 { 35 } 36 33 37 } // namespace KJS -
trunk/JavaScriptCore/kjs/identifier.h
r2766 r2769 58 58 friend bool operator==(const Identifier &, const char *); 59 59 60 static void aboutToDestroyUStringRep(UString::Rep *); 61 60 62 private: 61 63 UString _ustring; -
trunk/JavaScriptCore/kjs/property_map.cpp
r2766 r2769 65 65 } 66 66 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; 67 inline int PropertyMap::hash(const UString::Rep *s) const 68 { 69 return s->hash() & _tableSizeHashMask; 78 70 } 79 71 -
trunk/JavaScriptCore/kjs/ustring.cpp
r2762 r2769 37 37 #include "ustring.h" 38 38 #include "operations.h" 39 #include "identifier.h" 39 40 #include <math.h> 40 41 … … 115 116 116 117 UChar UChar::null((char)0); 117 UString::Rep UString::Rep::null = { 0, 0, 0, 1 };118 UString::Rep UString::Rep::empty = { 0, 0, 0, 1 };118 UString::Rep UString::Rep::null = { 0, 0, 0, 1, 1 }; 119 UString::Rep UString::Rep::empty = { 0, 0, 0, 1, 1 }; 119 120 UString UString::null; 120 121 const int normalStatBufferSize = 4096; … … 163 164 r->capacity = l; 164 165 r->rc = 1; 166 r->_hash = 0; 165 167 166 168 return r; 169 } 170 171 void UString::Rep::destroy() 172 { 173 if (capacity == capacityForIdentifier) 174 Identifier::aboutToDestroyUStringRep(this); 175 delete [] dat; 176 delete this; 177 } 178 179 void 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; 167 193 } 168 194 … … 329 355 memcpy(rep->dat+l, t.data(), tLen * sizeof(UChar)); 330 356 rep->len = newLen; 357 rep->_hash = 0; 331 358 return *this; 332 359 } … … 389 416 int l = c ? strlen(c) : 0; 390 417 UChar *d; 391 if (rep->rc == 1 && l < rep->capacity) {418 if (rep->rc == 1 && l <= rep->capacity) { 392 419 d = rep->dat; 420 rep->_hash = 0; 393 421 } else { 394 422 release(); -
trunk/JavaScriptCore/kjs/ustring.h
r2749 r2769 200 200 friend bool operator==(const UString&, const UString&); 201 201 friend class UCharReference; 202 friend class Identifier; 202 203 friend class PropertyMap; 203 204 friend class PropertyMapHashTableEntry; 205 204 206 /** 205 207 * @internal … … 208 210 friend class UString; 209 211 friend bool operator==(const UString&, const UString&); 212 210 213 static Rep *create(UChar *d, int l); 211 inline UChar *data() const { return dat; }212 inline int size() const { return len; }213 214 in line 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(); } 221 224 222 225 UChar *dat; … … 224 227 int capacity; 225 228 int rc; 229 mutable int _hash; 230 231 enum { capacityForIdentifier = 0x10000000 }; 232 226 233 static Rep null; 227 234 static Rep empty;
Note:
See TracChangeset
for help on using the changeset viewer.