Ignore:
Timestamp:
Oct 29, 2007, 12:55:34 AM (18 years ago)
Author:
eseidel
Message:

2007-10-29 Eric Seidel <[email protected]>

Reviewed by darin.


Give StringInstance a getOwnPropertySlot(ExecState, unsigned, PropertySlot) fastpath, just like Arrays.
Make it a compile time error to use toString(ExecState) on a StringInstance


SunSpider claims this was a 6.6% speedup overall (22% on string-base64)

  • kjs/internal.h: (KJS::StringImp::getLength):
  • kjs/string_object.cpp: (KJS::StringInstance::lengthGetter): (KJS::StringInstance::inlineGetOwnPropertySlot): (KJS::StringInstance::getOwnPropertySlot):
  • kjs/string_object.h:
File:
1 edited

Legend:

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

    r27202 r27218  
    6464}
    6565
    66 JSValue *StringInstance::lengthGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot &slot)
    67 {
    68     return jsNumber(static_cast<StringInstance*>(slot.slotBase())->internalValue()->toString(exec).size());
    69 }
    70 
    71 JSValue *StringInstance::indexGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot &slot)
    72 {
    73     const UChar c = static_cast<StringInstance *>(slot.slotBase())->internalValue()->toString(exec)[slot.index()];
     66JSValue *StringInstance::lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot &slot)
     67{
     68    return jsNumber(static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().size());
     69}
     70
     71JSValue *StringInstance::indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot &slot)
     72{
     73    const UChar c = static_cast<StringInstance*>(slot.slotBase())->internalValue()->value()[slot.index()];
    7474    return jsString(UString(&c, 1));
    7575}
    7676
    77 bool StringInstance::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)
    78 {
    79   if (propertyName == exec->propertyNames().length) {
    80     slot.setCustom(this, lengthGetter);
    81     return true;
    82   }
    83 
    84   bool ok;
    85   const unsigned index = propertyName.toArrayIndex(&ok);
    86   if (ok) {
    87     const UString s = internalValue()->toString(exec);
    88     const unsigned length = s.size();
    89     if (index < length) {
    90     slot.setCustomIndex(this, index, indexGetter);
    91     return true;
    92     }
    93   }
    94 
    95   return JSObject::getOwnPropertySlot(exec, propertyName, slot);
     77bool StringInstance::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
     78{
     79    if (propertyName == exec->propertyNames().length) {
     80        slot.setCustom(this, lengthGetter);
     81        return true;
     82    }
     83
     84    bool isStrictUInt32;
     85    unsigned i = propertyName.toStrictUInt32(&isStrictUInt32);
     86    unsigned length = internalValue()->value().size();
     87    if (isStrictUInt32 && i < length) {
     88        slot.setCustomIndex(this, i, indexGetter);
     89        return true;
     90    }
     91   
     92    return JSObject::getOwnPropertySlot(exec, propertyName, slot);
     93}
     94   
     95bool StringInstance::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
     96{
     97    unsigned length = internalValue()->value().size();
     98    if (propertyName < length) {
     99        slot.setCustomIndex(this, propertyName, indexGetter);
     100        return true;
     101    }
     102   
     103    return JSObject::getOwnPropertySlot(exec, Identifier::from(propertyName), slot);
    96104}
    97105
Note: See TracChangeset for help on using the changeset viewer.