Changeset 55599 in webkit for trunk/JavaScriptCore
- Timestamp:
- Mar 5, 2010, 3:29:13 PM (15 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r55564 r55599 1 2010-03-05 Oliver Hunt <[email protected]> 2 3 Reviewed by Gavin Barraclough. 4 5 JSC should cache int to Identifier conversion as it does for ordinary strings 6 https://bugs.webkit.org/show_bug.cgi?id=35814 7 8 Make the NumericStrings cache cache unsigned ints in addition to signed. 9 We keep them separate from the int cache as it both simplifies code, and 10 also because the unsigned path is exclusive to property access and therefore 11 seems to have different usage patterns. 12 13 The primary trigger for the unsigned to Identifier propertyName conversion 14 is the construction of array-like objects out of normal objects. Given these 15 tend to be relative small numbers, and the array-like behaviour lends itself 16 to sequential values this patch also adds a non-colliding cache for all small 17 numbers. 18 19 * JavaScriptCore.exp: 20 * runtime/Identifier.cpp: 21 (JSC::Identifier::from): 22 * runtime/Identifier.h: 23 * runtime/NumericStrings.h: 24 (JSC::NumericStrings::add): 25 (JSC::NumericStrings::lookup): 26 (JSC::NumericStrings::lookupSmallString): 27 1 28 2010-03-03 Oliver Hunt <[email protected]> 2 29 -
trunk/JavaScriptCore/JavaScriptCore.exp
r55401 r55599 96 96 __ZN3JSC10Identifier24checkSameIdentifierTableEPNS_9ExecStateEPNS_11UStringImplE 97 97 __ZN3JSC10Identifier3addEPNS_9ExecStateEPKc 98 __ZN3JSC10Identifier4fromEPNS_9ExecStateEi 99 __ZN3JSC10Identifier4fromEPNS_9ExecStateEj 98 100 __ZN3JSC10Identifier5equalEPKNS_11UStringImplEPKc 99 101 __ZN3JSC10JSFunctionC1EPNS_9ExecStateEN3WTF17NonNullPassRefPtrINS_9StructureEEEiRKNS_10IdentifierEPFNS_7JSValueES2_PNS_8JSObjectESA_RKNS_7ArgListEE -
trunk/JavaScriptCore/runtime/Identifier.cpp
r54843 r55599 23 23 24 24 #include "CallFrame.h" 25 #include "NumericStrings.h" 25 26 #include <new> // for placement new 26 27 #include <string.h> // for strlen … … 237 238 currentIdentifierTable()->remove(r); 238 239 } 240 241 Identifier Identifier::from(ExecState* exec, unsigned value) 242 { 243 return Identifier(exec, exec->globalData().numericStrings.add(value)); 244 } 245 246 Identifier Identifier::from(ExecState* exec, int value) 247 { 248 return Identifier(exec, exec->globalData().numericStrings.add(value)); 249 } 250 251 Identifier Identifier::from(ExecState* exec, double value) 252 { 253 return Identifier(exec, exec->globalData().numericStrings.add(value)); 254 } 239 255 240 256 #ifndef NDEBUG -
trunk/JavaScriptCore/runtime/Identifier.h
r54789 r55599 55 55 const char* ascii() const { return _ustring.ascii(); } 56 56 57 static Identifier from(ExecState* exec, unsigned y) { return Identifier(exec, UString::from(y)); }58 static Identifier from(ExecState* exec, int y) { return Identifier(exec, UString::from(y)); }59 static Identifier from(ExecState* exec, double y) { return Identifier(exec, UString::from(y)); }57 static Identifier from(ExecState* exec, unsigned y); 58 static Identifier from(ExecState* exec, int y); 59 static Identifier from(ExecState* exec, double y); 60 60 61 61 bool isNull() const { return _ustring.isNull(); } -
trunk/JavaScriptCore/runtime/NumericStrings.h
r47622 r55599 46 46 UString add(int i) 47 47 { 48 if (static_cast<unsigned>(i) < cacheSize) 49 return lookupSmallString(static_cast<unsigned>(i)); 48 50 CacheEntry<int>& entry = lookup(i); 49 51 if (i == entry.key && !entry.value.isNull()) … … 54 56 } 55 57 58 UString add(unsigned i) 59 { 60 if (i < cacheSize) 61 return lookupSmallString(static_cast<unsigned>(i)); 62 CacheEntry<unsigned>& entry = lookup(i); 63 if (i == entry.key && !entry.value.isNull()) 64 return entry.value; 65 entry.key = i; 66 entry.value = UString::from(i); 67 return entry.value; 68 } 56 69 private: 57 70 static const size_t cacheSize = 64; … … 65 78 CacheEntry<double>& lookup(double d) { return doubleCache[WTF::FloatHash<double>::hash(d) & (cacheSize - 1)]; } 66 79 CacheEntry<int>& lookup(int i) { return intCache[WTF::IntHash<int>::hash(i) & (cacheSize - 1)]; } 80 CacheEntry<unsigned>& lookup(unsigned i) { return unsignedCache[WTF::IntHash<unsigned>::hash(i) & (cacheSize - 1)]; } 81 const UString& lookupSmallString(unsigned i) 82 { 83 ASSERT(i < cacheSize); 84 if (smallIntCache[i].isNull()) 85 smallIntCache[i] = UString::from(i); 86 return smallIntCache[i]; 87 } 67 88 68 89 CacheEntry<double> doubleCache[cacheSize]; 69 90 CacheEntry<int> intCache[cacheSize]; 91 CacheEntry<unsigned> unsignedCache[cacheSize]; 92 UString smallIntCache[cacheSize]; 70 93 }; 71 94
Note:
See TracChangeset
for help on using the changeset viewer.