Changeset 34964 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jul 2, 2008, 5:47:00 PM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r34962 r34964 1 2008-07-02 Geoffrey Garen <[email protected]> 2 3 Reviewed by Oliver Hunt. 4 5 Optimized a[n] get for cases where a is an array or a string, and a[n] 6 put for cases where a is an array. 7 8 SunSpider says 9.0% faster. 9 1 10 2008-07-02 Kevin McCullough <[email protected]> 2 11 -
trunk/JavaScriptCore/VM/Machine.cpp
r34947 r34964 46 46 #include "RegExpPrototype.h" 47 47 #include "Register.h" 48 #include "collector.h" 48 49 #include "debugger.h" 49 50 #include "operations.h" … … 476 477 { 477 478 privateExecute(InitializeAndReturn); 479 480 // Bizarrely, calling fastMalloc here is faster than allocating space on the stack. 481 void* storage = fastMalloc(sizeof(CollectorBlock)); 482 483 JSArray* jsArray = new (storage) JSArray(jsNull(), 0); 484 m_jsArrayVptr = jsArray->vptr(); 485 jsArray->~JSCell(); 486 487 JSString* jsString = new (storage) JSString(""); 488 m_jsStringVptr = jsString->vptr(); 489 jsString->~JSCell(); 490 491 fastFree(storage); 478 492 } 479 493 … … 1835 1849 1836 1850 bool isUInt32 = JSImmediate::getUInt32(subscript, i); 1837 if (LIKELY(isUInt32)) 1838 result = baseValue->get(exec, i); 1839 else { 1851 if (LIKELY(isUInt32)) { 1852 if (isJSArray(baseValue)) { 1853 JSArray* jsArray = static_cast<JSArray*>(baseValue); 1854 if (jsArray->canGetIndex(i)) 1855 result = jsArray->getIndex(i); 1856 else 1857 result = jsArray->JSArray::get(exec, i); 1858 } else if (isJSString(baseValue) && static_cast<JSString*>(baseValue)->canGetIndex(i)) 1859 result = static_cast<JSString*>(baseValue)->getIndex(exec, i); 1860 else 1861 result = baseValue->get(exec, i); 1862 } else { 1840 1863 Identifier property(exec, subscript->toString(exec)); 1841 1864 result = baseValue->get(exec, property); … … 1868 1891 1869 1892 bool isUInt32 = JSImmediate::getUInt32(subscript, i); 1870 if (LIKELY(isUInt32)) 1871 baseValue->put(exec, i, r[value].u.jsValue); 1872 else { 1893 if (LIKELY(isUInt32)) { 1894 if (isJSArray(baseValue)) { 1895 JSArray* jsArray = static_cast<JSArray*>(baseValue); 1896 if (jsArray->canSetIndex(i)) 1897 jsArray->setIndex(i, r[value].u.jsValue); 1898 else 1899 jsArray->JSArray::put(exec, i, r[value].u.jsValue); 1900 } else 1901 baseValue->put(exec, i, r[value].u.jsValue); 1902 } else { 1873 1903 Identifier property(exec, subscript->toString(exec)); 1874 1904 if (!exec->hadException()) // Don't put to an object if toString threw an exception. -
trunk/JavaScriptCore/VM/Machine.h
r34907 r34964 30 30 #define Machine_h 31 31 32 #include "JSCell.h" 33 #include "JSValue.h" 32 34 #include "Opcode.h" 33 35 #include "RegisterFile.h" … … 141 143 void resetTimeoutCheck(); 142 144 145 bool isJSArray(JSValue* v) { return !JSImmediate::isImmediate(v) && v->asCell()->vptr() == m_jsArrayVptr; } 146 bool isJSString(JSValue* v) { return !JSImmediate::isImmediate(v) && v->asCell()->vptr() == m_jsStringVptr; } 147 143 148 int m_reentryDepth; 144 149 unsigned m_timeoutTime; … … 149 154 150 155 RegisterFile m_registerFile; 156 157 void* m_jsArrayVptr; 158 void* m_jsStringVptr; 151 159 152 160 #if HAVE(COMPUTED_GOTO) -
trunk/JavaScriptCore/kjs/JSArray.cpp
r34868 r34964 35 35 namespace KJS { 36 36 37 typedef HashMap<unsigned, JSValue*> SparseArrayValueMap;38 39 struct ArrayStorage {40 unsigned m_vectorLength;41 unsigned m_numValuesInVector;42 SparseArrayValueMap* m_sparseValueMap;43 void* lazyCreationData; // An JSArray subclass can use this to fill the vector lazily.44 JSValue* m_vector[1];45 };46 47 37 // 0xFFFFFFFF is a bit weird -- is not an array index even though it's an integer. 48 38 static const unsigned maxArrayIndex = 0xFFFFFFFEU; … … 82 72 #endif 83 73 84 JSArray::JSArray(JS Object* prototype, unsigned initialLength)74 JSArray::JSArray(JSValue* prototype, unsigned initialLength) 85 75 : JSObject(prototype) 86 76 { -
trunk/JavaScriptCore/kjs/JSArray.h
r34868 r34964 27 27 namespace KJS { 28 28 29 struct ArrayStorage; 29 typedef HashMap<unsigned, JSValue*> SparseArrayValueMap; 30 31 struct ArrayStorage { 32 unsigned m_vectorLength; 33 unsigned m_numValuesInVector; 34 SparseArrayValueMap* m_sparseValueMap; 35 void* lazyCreationData; // A JSArray subclass can use this to fill the vector lazily. 36 JSValue* m_vector[1]; 37 }; 30 38 31 39 class JSArray : public JSObject { 32 40 public: 33 JSArray(JS Object* prototype, unsigned initialLength);41 JSArray(JSValue* prototype, unsigned initialLength); 34 42 JSArray(JSObject* prototype, const ArgList& initialValues); 35 43 virtual ~JSArray(); … … 46 54 void sort(ExecState*); 47 55 void sort(ExecState*, JSValue* compareFunction, CallType, const CallData&); 56 57 bool canGetIndex(unsigned i) { return i < m_fastAccessCutoff; } 58 JSValue* getIndex(unsigned i) 59 { 60 ASSERT(canGetIndex(i)); 61 return m_storage->m_vector[i]; 62 } 63 64 bool canSetIndex(unsigned i) { return i < m_fastAccessCutoff; } 65 JSValue* setIndex(unsigned i, JSValue* v) 66 { 67 ASSERT(canSetIndex(i)); 68 return m_storage->m_vector[i] = v; 69 } 48 70 49 71 protected: -
trunk/JavaScriptCore/kjs/JSCell.h
r34921 r34964 37 37 friend class JSNumberCell; 38 38 friend class JSString; 39 friend class Machine; 39 40 private: 40 41 JSCell(); … … 75 76 // Garbage collection. 76 77 void* operator new(size_t, ExecState*); 78 void* operator new(size_t, void* placementNewDestination) { return placementNewDestination; } 77 79 virtual void mark(); 78 80 bool marked() const; … … 89 91 virtual JSString* toThisJSString(ExecState*); 90 92 virtual JSValue* getJSNumber(); 93 void* vptr() { return *reinterpret_cast<void**>(this); } 91 94 92 95 private: -
trunk/JavaScriptCore/kjs/JSString.h
r34921 r34964 43 43 bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); 44 44 bool getStringPropertySlot(unsigned propertyName, PropertySlot&); 45 46 bool canGetIndex(unsigned i) { return i < static_cast<unsigned>(m_value.size()); } 47 JSValue* getIndex(ExecState* exec, unsigned i) 48 { 49 ASSERT(canGetIndex(i)); 50 return new (exec) JSString(m_value.substr(i, 1)); 51 } 45 52 46 53 private: -
trunk/JavaScriptCore/kjs/JSValue.h
r34921 r34964 53 53 friend class JSCell; // so it can derive from this class 54 54 friend class Heap; // so it can call asCell() 55 friend class Machine; // so it can call asCell() 55 56 private: 56 57 JSValue();
Note:
See TracChangeset
for help on using the changeset viewer.