Changeset 35806 in webkit for trunk/JavaScriptCore
- Timestamp:
- Aug 17, 2008, 12:57:39 AM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r35805 r35806 1 2008-08-16 Geoffrey Garen <[email protected]> 2 3 Reviewed by Oliver Hunt. 4 5 Sped up property access for array.length and string.length by adding a 6 mechanism for returning a temporary value directly instead of returning 7 a pointer to a function that retrieves the value. 8 9 Also removed some unused cruft from PropertySlot. 10 11 SunSpider says 0.5% - 1.2% faster. 12 13 NOTE: This optimization is not a good idea in general, because it's 14 actually a pessimization in the case of resolve for assignment, 15 and it may get in the way of other optimizations in the future. 16 1 17 2008-08-16 Dan Bernstein <[email protected]> 2 18 -
trunk/JavaScriptCore/JavaScriptCore.exp
r35777 r35806 104 104 __ZN3KJS12JSGlobalData6createEv 105 105 __ZN3KJS12JSGlobalDataD1Ev 106 __ZN3KJS12PropertySlot15undefinedGetterEPNS_9ExecStateERKNS_10IdentifierERKS0_107 106 __ZN3KJS12SamplingTool4dumpEPNS_9ExecStateE 108 107 __ZN3KJS12SamplingTool4stopEv -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r35805 r35806 1626 1626 projectDirPath = ""; 1627 1627 projectRoot = ""; 1628 projectRoots = (1629 "",1630 );1631 1628 targets = ( 1632 1629 932F5BE30822A1C700736975 /* All */, -
trunk/JavaScriptCore/kjs/JSArray.cpp
r35691 r35806 174 174 } 175 175 176 JSValue* JSArray::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)177 {178 return jsNumber(exec, static_cast<JSArray*>(slot.slotBase())->m_length);179 }180 181 176 bool JSArray::getOwnPropertySlot(ExecState* exec, unsigned i, PropertySlot& slot) 182 177 { … … 211 206 { 212 207 if (propertyName == exec->propertyNames().length) { 213 slot.set Custom(this, lengthGetter);208 slot.setValue(jsNumber(exec, getLength())); 214 209 return true; 215 210 } -
trunk/JavaScriptCore/kjs/JSArray.h
r35291 r35806 82 82 virtual const ClassInfo* classInfo() const { return &info; } 83 83 84 static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&);85 86 84 bool getOwnPropertySlotSlowCase(ExecState*, unsigned propertyName, PropertySlot&); 87 85 void putSlowCase(ExecState*, unsigned propertyName, JSValue*); -
trunk/JavaScriptCore/kjs/JSString.cpp
r35027 r35806 83 83 } 84 84 85 JSValue* JSString::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)86 {87 return jsNumber(exec, static_cast<JSString*>(slot.slotBase())->value().size());88 }89 90 JSValue* JSString::indexGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)91 {92 return jsString(exec, static_cast<JSString*>(slot.slotBase())->value().substr(slot.index(), 1));93 }94 95 JSValue* JSString::indexNumericPropertyGetter(ExecState* exec, unsigned index, const PropertySlot& slot)96 {97 return jsString(exec, static_cast<JSString*>(slot.slotBase())->value().substr(index, 1));98 }99 100 85 bool JSString::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 101 86 { … … 120 105 // The semantics here are really getPropertySlot, not getOwnPropertySlot. 121 106 // This function should only be called by JSValue::get. 122 if (getStringPropertySlot( propertyName, slot))107 if (getStringPropertySlot(exec, propertyName, slot)) 123 108 return true; 124 109 return JSString::getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot); -
trunk/JavaScriptCore/kjs/JSString.h
r35203 r35806 28 28 #include "ExecState.h" 29 29 #include "JSCell.h" 30 #include "JSNumberCell.h" 30 31 #include "PropertySlot.h" 31 32 #include "identifier.h" … … 51 52 52 53 bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); 53 bool getStringPropertySlot( unsigned propertyName, PropertySlot&);54 bool getStringPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); 54 55 55 56 bool canGetIndex(unsigned i) { return i < static_cast<unsigned>(m_value.size()); } … … 78 79 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); 79 80 80 static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&);81 static JSValue* indexGetter(ExecState*, const Identifier&, const PropertySlot&);82 static JSValue* indexNumericPropertyGetter(ExecState*, unsigned, const PropertySlot&);83 84 81 UString m_value; 85 82 }; … … 96 93 { 97 94 if (propertyName == exec->propertyNames().length) { 98 slot.set Custom(this, lengthGetter);95 slot.setValue(jsNumber(exec, value().size())); 99 96 return true; 100 97 } … … 103 100 unsigned i = propertyName.toStrictUInt32(&isStrictUInt32); 104 101 if (isStrictUInt32 && i < static_cast<unsigned>(m_value.size())) { 105 slot.set CustomIndex(this, i, indexGetter);102 slot.setValue(jsString(exec, value().substr(i, 1))); 106 103 return true; 107 104 } … … 110 107 } 111 108 112 ALWAYS_INLINE bool JSString::getStringPropertySlot( unsigned propertyName, PropertySlot& slot)109 ALWAYS_INLINE bool JSString::getStringPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot) 113 110 { 114 111 if (propertyName < static_cast<unsigned>(m_value.size())) { 115 slot.set CustomNumeric(this, indexNumericPropertyGetter);112 slot.setValue(jsString(exec, value().substr(propertyName, 1))); 116 113 return true; 117 114 } -
trunk/JavaScriptCore/kjs/PropertySlot.cpp
r35242 r35806 28 28 namespace KJS { 29 29 30 JSValue* PropertySlot::undefinedGetter(ExecState*, const Identifier&, const PropertySlot&)31 {32 return jsUndefined();33 }34 35 30 JSValue* PropertySlot::functionGetter(ExecState* exec, const Identifier&, const PropertySlot& slot) 36 31 { -
trunk/JavaScriptCore/kjs/PropertySlot.h
r35291 r35806 35 35 #define KJS_VALUE_SLOT_MARKER 0 36 36 #define KJS_REGISTER_SLOT_MARKER reinterpret_cast<GetValueFunc>(1) 37 #define KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER reinterpret_cast<GetValueFunc>(2)38 37 39 38 class PropertySlot { … … 42 41 { 43 42 clearBase(); 43 clearValue(); 44 44 } 45 45 … … 47 47 : m_slotBase(base) 48 48 { 49 clearValue(); 49 50 } 50 51 51 52 typedef JSValue* (*GetValueFunc)(ExecState*, const Identifier&, const PropertySlot&); 52 typedef JSValue* (*GetValueNumericFunc)(ExecState*, unsigned index, const PropertySlot&);53 53 54 54 JSValue* getValue(ExecState* exec, const Identifier& propertyName) const … … 58 58 if (m_getValue == KJS_REGISTER_SLOT_MARKER) 59 59 return (*m_data.registerSlot).jsValue(exec); 60 ASSERT(m_getValue != KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER);61 60 return m_getValue(exec, propertyName, *this); 62 61 } … … 66 65 if (m_getValue == KJS_VALUE_SLOT_MARKER) 67 66 return *m_data.valueSlot; 68 if (m_getValue == KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER)69 return m_data.numericFunc(exec, propertyName, *this);70 67 if (m_getValue == KJS_REGISTER_SLOT_MARKER) 71 68 return (*m_data.registerSlot).jsValue(exec); … … 91 88 } 92 89 90 void setValue(JSValue* value) 91 { 92 ASSERT(value); 93 m_getValue = KJS_VALUE_SLOT_MARKER; 94 clearBase(); 95 m_value = value; 96 m_data.valueSlot = &m_value; 97 } 98 93 99 void setRegisterSlot(Register* registerSlot) 94 100 { … … 126 132 } 127 133 128 void setCustomNumeric(JSValue* slotBase, GetValueNumericFunc getValue)129 {130 ASSERT(slotBase);131 ASSERT(getValue);132 m_slotBase = slotBase;133 m_getValue = KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER;134 m_data.numericFunc = getValue;135 }136 137 134 void setGetterSlot(JSObject* getterFunc) 138 135 { … … 145 142 { 146 143 clearBase(); 147 m_getValue = undefinedGetter;144 setValue(jsUndefined()); 148 145 } 149 146 … … 168 165 } 169 166 167 void clearValue() 168 { 169 #ifndef NDEBUG 170 m_value = 0; 171 #endif 172 } 173 170 174 const HashEntry* staticEntry() const { return m_data.staticEntry; } 171 175 unsigned index() const { return m_data.index; } 172 176 173 177 private: 174 static JSValue* undefinedGetter(ExecState*, const Identifier&, const PropertySlot&);175 178 static JSValue* functionGetter(ExecState*, const Identifier&, const PropertySlot&); 176 179 177 180 GetValueFunc m_getValue; 181 182 JSValue* m_value; 178 183 179 184 JSValue* m_slotBase; … … 184 189 const HashEntry* staticEntry; 185 190 unsigned index; 186 GetValueNumericFunc numericFunc;187 191 } m_data; 188 192 }; -
trunk/JavaScriptCore/kjs/StringObject.cpp
r35027 r35806 55 55 bool StringObject::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot) 56 56 { 57 if (internalValue()->getStringPropertySlot( propertyName, slot))57 if (internalValue()->getStringPropertySlot(exec, propertyName, slot)) 58 58 return true; 59 59 return JSObject::getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
Note:
See TracChangeset
for help on using the changeset viewer.