Changeset 36015 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Sep 1, 2008, 12:51:33 PM (17 years ago)
Author:
[email protected]
Message:

2008-09-01 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.

Eagerly allocate the Math object's numeric constants. This avoids
constantly reallocating them in loops, and also ensures that the Math
object will not use the single property optimization, which makes
properties ineligible for caching.

SunSpider reports a small speedup, in combination with inline caching.

  • kjs/MathObject.cpp: (KJS::MathObject::MathObject): (KJS::MathObject::getOwnPropertySlot):
  • kjs/MathObject.h:
Location:
trunk/JavaScriptCore/kjs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/MathObject.cpp

    r35807 r36015  
    6363/* Source for MathObject.lut.h
    6464@begin mathTable
    65   E             MathObject::Euler           DontEnum|DontDelete|ReadOnly
    66   LN2           MathObject::Ln2             DontEnum|DontDelete|ReadOnly
    67   LN10          MathObject::Ln10            DontEnum|DontDelete|ReadOnly
    68   LOG2E         MathObject::Log2E           DontEnum|DontDelete|ReadOnly
    69   LOG10E        MathObject::Log10E          DontEnum|DontDelete|ReadOnly
    70   PI            MathObject::Pi              DontEnum|DontDelete|ReadOnly
    71   SQRT1_2       MathObject::Sqrt1_2         DontEnum|DontDelete|ReadOnly
    72   SQRT2         MathObject::Sqrt2           DontEnum|DontDelete|ReadOnly
    7365  abs           mathProtoFuncAbs               DontEnum|Function 1
    7466  acos          mathProtoFuncACos              DontEnum|Function 1
     
    9284*/
    9385
    94 MathObject::MathObject(ExecState*, ObjectPrototype* objectPrototype)
     86MathObject::MathObject(ExecState* exec, ObjectPrototype* objectPrototype)
    9587    : JSObject(objectPrototype)
    9688{
     89    putDirect(Identifier(exec, "E"), jsNumber(exec, exp(1.0)), DontDelete | DontEnum | ReadOnly);
     90    putDirect(Identifier(exec, "LN2"), jsNumber(exec, log(2.0)), DontDelete | DontEnum | ReadOnly);
     91    putDirect(Identifier(exec, "LN10"), jsNumber(exec, log(10.0)), DontDelete | DontEnum | ReadOnly);
     92    putDirect(Identifier(exec, "LOG2E"), jsNumber(exec, 1.0 / log(2.0)), DontDelete | DontEnum | ReadOnly);
     93    putDirect(Identifier(exec, "LOG10E"), jsNumber(exec, 1.0 / log(10.0)), DontDelete | DontEnum | ReadOnly);
     94    putDirect(Identifier(exec, "PI"), jsNumber(exec, piDouble), DontDelete | DontEnum | ReadOnly);
     95    putDirect(Identifier(exec, "SQRT1_2"), jsNumber(exec, sqrt(0.5)), DontDelete | DontEnum | ReadOnly);
     96    putDirect(Identifier(exec, "SQRT2"), jsNumber(exec, sqrt(2.0)), DontDelete | DontEnum | ReadOnly);
    9797}
    9898
     
    101101bool MathObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot &slot)
    102102{
    103     return getStaticPropertySlot<MathObject, JSObject>(exec, ExecState::mathTable(exec), this, propertyName, slot);
    104 }
    105 
    106 JSValue* MathObject::getValueProperty(ExecState* exec, int token) const
    107 {
    108     switch (token) {
    109         case Euler:
    110             return jsNumber(exec, exp(1.0));
    111         case Ln2:
    112             return jsNumber(exec, log(2.0));
    113         case Ln10:
    114             return jsNumber(exec, log(10.0));
    115         case Log2E:
    116             return jsNumber(exec, 1.0 / log(2.0));
    117         case Log10E:
    118             return jsNumber(exec, 1.0 / log(10.0));
    119         case Pi:
    120             return jsNumber(exec, piDouble);
    121         case Sqrt1_2:
    122             return jsNumber(exec, sqrt(0.5));
    123         case Sqrt2:
    124             return jsNumber(exec, sqrt(2.0));
    125     }
    126 
    127     ASSERT_NOT_REACHED();
    128     return 0;
     103    const HashEntry* entry = ExecState::mathTable(exec)->entry(exec, propertyName);
     104
     105    if (!entry)
     106        return JSObject::getOwnPropertySlot(exec, propertyName, slot);
     107
     108    ASSERT(entry->attributes & Function);
     109    slot.setStaticEntry(this, entry, staticFunctionGetter);
     110    return true;
    129111}
    130112
  • trunk/JavaScriptCore/kjs/MathObject.h

    r34854 r36015  
    3131
    3232        bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
    33         JSValue* getValueProperty(ExecState*, int token) const;
    3433
    3534        virtual const ClassInfo* classInfo() const { return &info; }
    3635        static const ClassInfo info;
    37 
    38         enum { Euler, Ln2, Ln10, Log2E, Log10E, Pi, Sqrt1_2, Sqrt2 };
    3936    };
    4037
Note: See TracChangeset for help on using the changeset viewer.