Changeset 31226

Show
Ignore:
Timestamp:
2008-03-21 21:59:20 (5 months ago)
Author:
oliver@apple.com
Message:

Optimise lookup of Math, undefined, NaN and Infinity

Reviewed by Maciej

Added a method to JSVariableObject to allow us to inject DontDelete properties
into the symbol table and localStorage. This results in a 0.4% progression in
SunSpider, with a 8% gain in math-partial-sums.

Location:
trunk/JavaScriptCore
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r31225 r31226  
     12008-03-21  Oliver Hunt  <oliver@apple.com> 
     2 
     3        Reviewed by Maciej. 
     4 
     5        Optimise lookup of Math, undefined, NaN and Infinity 
     6 
     7        Added a method to JSVariableObject to allow us to inject DontDelete properties 
     8        into the symbol table and localStorage.  This results in a 0.4% progression in 
     9        SunSpider, with a 8% gain in math-partial-sums. 
     10 
     11        * kjs/JSGlobalObject.cpp: 
     12        (KJS::JSGlobalObject::reset): 
     13        * kjs/JSVariableObject.h: 
     14        (KJS::JSVariableObject::symbolTableInsert): 
     15 
    1162008-03-21  Oliver Hunt  <oliver@apple.com> 
    217 
  • trunk/JavaScriptCore/kjs/JSGlobalObject.cpp

    r31173 r31226  
    310310 
    311311    // Set global values. 
    312  
    313     putDirect("Math", new MathObjectImp(exec, d()->objectPrototype), DontEnum); 
    314  
    315     putDirect("NaN", jsNaN(), DontEnum | DontDelete); 
    316     putDirect("Infinity", jsNumber(Inf), DontEnum | DontDelete); 
    317     putDirect("undefined", jsUndefined(), DontEnum | DontDelete); 
     312    Identifier mathIdent = "Math"; 
     313    JSValue* mathObject = new MathObjectImp(exec, d()->objectPrototype); 
     314    symbolTableInsert(mathIdent, mathObject, DontEnum | DontDelete); 
     315     
     316    Identifier nanIdent = "NaN"; 
     317    JSValue* nanValue = jsNaN(); 
     318    symbolTableInsert(nanIdent, nanValue, DontEnum | DontDelete); 
     319     
     320    Identifier infinityIdent = "Infinity"; 
     321    JSValue* infinityValue = jsNumber(Inf); 
     322    symbolTableInsert(infinityIdent, infinityValue, DontEnum | DontDelete); 
     323     
     324    Identifier undefinedIdent = "undefined"; 
     325    JSValue* undefinedValue = jsUndefined(); 
     326    symbolTableInsert(undefinedIdent, undefinedValue, DontEnum | DontDelete); 
    318327 
    319328    // Set global functions. 
  • trunk/JavaScriptCore/kjs/JSVariableObject.h

    r31225 r31226  
    8787        bool symbolTablePut(const Identifier&, JSValue*); 
    8888        bool symbolTableInitializeVariable(const Identifier&, JSValue*, unsigned attributes); 
     89        bool symbolTableInsert(const Identifier&, JSValue*, unsigned attributes); 
    8990 
    9091        JSVariableObjectData* d; 
     
    135136        return true; 
    136137    } 
     138     
     139    inline bool JSVariableObject::symbolTableInsert(const Identifier& propertyName, JSValue* value, unsigned attributes) 
     140    { 
     141        if (symbolTable().get(propertyName.ustring().rep()) != missingSymbolMarker()) 
     142            return false; 
    137143 
     144        ASSERT((attributes & DontDelete) != 0); 
     145        size_t localStorageIndex = d->localStorage.size(); 
     146        d->localStorage.append(LocalStorageEntry(value, attributes)); 
     147        symbolTable().add(propertyName.ustring().rep(), localStorageIndex); 
     148        return true; 
     149    } 
    138150} // namespace KJS 
    139151