Changeset 34518 in webkit for trunk/JavaScriptCore/kjs/internal.h


Ignore:
Timestamp:
Jun 12, 2008, 9:53:56 PM (17 years ago)
Author:
Darin Adler
Message:

2008-06-12 Darin Adler <Darin Adler>

Reviewed by Maciej.

Speeds up SunSpider by 1.1%.

Optimized code path for getting built-in properties from strings -- avoid
boxing with a string object in that case. We can make further changes to avoid
even more boxing, but this change alone is a win.

  • API/JSCallbackObjectFunctions.h: (KJS::JSCallbackObject::staticValueGetter): Use isObject instead of inherits in asssert, since the type of slotBase() is now JSValue, not JSObject. (KJS::JSCallbackObject::staticFunctionGetter): Ditto. (KJS::JSCallbackObject::callbackGetter): Ditto.
  • kjs/internal.cpp: (KJS::StringImp::getPrimitiveNumber): Updated for change of data member name. (KJS::StringImp::toBoolean): Ditto. (KJS::StringImp::toNumber): Ditto. (KJS::StringImp::toString): Ditto. (KJS::StringInstance::create): Added; avoids a bit of cut and paste code. (KJS::StringImp::toObject): Use StringInstance::create. (KJS::StringImp::toThisObject): Ditto. (KJS::StringImp::lengthGetter): Added. Replaces the getter that used to live in the StringInstance class. (KJS::StringImp::indexGetter): Ditto. (KJS::StringImp::indexNumericPropertyGetter): Ditto. (KJS::StringImp::getOwnPropertySlot): Added. Deals with built in properties of the string class without creating a StringInstance.
  • kjs/internal.h: (KJS::StringImp::getStringPropertySlot): Added. To be used by both the string and string object getOwnPropertySlot function.
  • kjs/lookup.h: (KJS::staticFunctionGetter): Updated since slotBase() is now a JSValue rather than a JSObject.
  • kjs/object.h: Removed PropertySlot::slotBase() function, which can now move back into property_slot.h where it belongs since it doesn't have to cast to JSObject*.
  • kjs/property_slot.cpp: (KJS::PropertySlot::functionGetter): Updated since slot.slotBase() is now a JSValue* instead of JSObject*. setGetterSlot still guarantees the base is a JSObject*.
  • kjs/property_slot.h: (KJS::PropertySlot::PropertySlot): Changed base to JSValue* intead of JSCell*. (KJS::PropertySlot::setStaticEntry): Ditto. (KJS::PropertySlot::setCustom): Ditto. (KJS::PropertySlot::setCustomIndex): Ditto. (KJS::PropertySlot::setCustomNumeric): Ditto. (KJS::PropertySlot::slotBase): Moved inline here since it no longer involves a downcast to JSObject*. (KJS::PropertySlot::setBase): Changed to JSValue*.
  • kjs/string_object.cpp: (KJS::StringInstance::getOwnPropertySlot): Changed to use getStringPropertySlot instead of coding the properties here. This allows sharing the code with StringImp.
  • kjs/string_object.h: Removed inlineGetOwnPropertySlot, lengthGetter, and indexGetter. Made one of the constructors protected.
  • kjs/value.h: Made getOwnPropertySlot private in the JSCell class -- this is better since it's not the real JSObject getOwnPropertySlot semantic and most callers shouldn't use it.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/internal.h

    r34355 r34518  
    33 *  Copyright (C) 1999-2001 Harri Porten ([email protected])
    44 *  Copyright (C) 2001 Peter Kelly ([email protected])
    5  *  Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
     5 *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
    66 *
    77 *  This library is free software; you can redistribute it and/or
     
    2525#define INTERNAL_H
    2626
    27 #include "JSType.h"
    2827#include "object.h"
    29 #include "protect.h"
    30 #include "scope_chain.h"
    31 #include "types.h"
    3228#include "ustring.h"
    33 
    34 #include <wtf/Noncopyable.h>
    35 
    36 #define I18N_NOOP(s) s
    3729
    3830namespace KJS {
    3931
    40   class FunctionPrototype;
    41 
    42   // ---------------------------------------------------------------------------
    43   //                            Primitive impls
    44   // ---------------------------------------------------------------------------
    45 
    4632  class StringImp : public JSCell {
    4733  public:
    48     StringImp(const UString& v) : val(v) { Collector::reportExtraMemoryCost(v.cost()); }
     34    StringImp(const UString& value) : m_value(value) { Collector::reportExtraMemoryCost(value.cost()); }
    4935    enum HasOtherOwnerType { HasOtherOwner };
    50     StringImp(const UString& value, HasOtherOwnerType) : val(value) { }
    51     const UString& value() const { return val; }
     36    StringImp(const UString& value, HasOtherOwnerType) : m_value(value) { }
     37
     38    const UString& value() const { return m_value; }
     39
     40    bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
     41    bool getStringPropertySlot(unsigned propertyName, PropertySlot&);
    5242
    5343  private:
     
    5646    virtual JSValue* toPrimitive(ExecState*, JSType preferred = UnspecifiedType) const;
    5747    virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
    58     virtual bool toBoolean(ExecState *exec) const;
    59     virtual double toNumber(ExecState *exec) const;
    60     virtual JSObject *toObject(ExecState *exec) const;
     48    virtual bool toBoolean(ExecState*) const;
     49    virtual double toNumber(ExecState*) const;
     50    virtual JSObject* toObject(ExecState*) const;
    6151    virtual UString toString(ExecState*) const;
    6252    virtual JSObject* toThisObject(ExecState*) const;
    6353
    64     UString val;
     54    // Actually getPropertySlot, not getOwnPropertySlot (see JSCell).
     55    virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
     56    virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
     57
     58    static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
     59    static JSValue* indexGetter(ExecState*, const Identifier&, const PropertySlot&);
     60    static JSValue* indexNumericPropertyGetter(ExecState*, unsigned, const PropertySlot&);
     61
     62    UString m_value;
    6563  };
    6664
    67   // ---------------------------------------------------------------------------
    68   //                            Evaluation
    69   // ---------------------------------------------------------------------------
     65ALWAYS_INLINE bool StringImp::getStringPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
     66{
     67    if (propertyName == exec->propertyNames().length) {
     68        slot.setCustom(this, lengthGetter);
     69        return true;
     70    }
     71
     72    bool isStrictUInt32;
     73    unsigned i = propertyName.toStrictUInt32(&isStrictUInt32);
     74    if (isStrictUInt32 && i < static_cast<unsigned>(m_value.size())) {
     75        slot.setCustomIndex(this, i, indexGetter);
     76        return true;
     77    }
     78
     79    return false;
     80}
     81   
     82ALWAYS_INLINE bool StringImp::getStringPropertySlot(unsigned propertyName, PropertySlot& slot)
     83{
     84    if (propertyName < static_cast<unsigned>(m_value.size())) {
     85        slot.setCustomNumeric(this, indexNumericPropertyGetter);
     86        return true;
     87    }
     88
     89    return false;
     90}
    7091
    7192} // namespace
Note: See TracChangeset for help on using the changeset viewer.