Commit b8a5a8e5 authored by darin@apple.com's avatar darin@apple.com
Browse files

Reviewed by Maciej.

        - http://bugs.webkit.org/show_bug.cgi?id=15906
          getting characters by indexing into a string is very slow

        This fixes one source of the slowness -- the conversion to an unused
        Identifier as we call the get function from the slot -- but doesn't
        fix others, such as the fact that we have to allocate a new UString::Rep
        for every single character.

        Speeds up string-base64 30%, and at least 0.5% overall.
        But does slow down access-fannkuch quite a bit. Might be worth
        revisiting in the future to see what we can do about that (although
        I did look at a profile for a while).

        * kjs/property_slot.h: Add a new marker for "numeric" property slots;
        slots where we don't need to pass the identifier to the get function.
        (KJS::PropertySlot::getValue): Added code to call the numeric get function.
        (KJS::PropertySlot::setCustomNumeric): Added.
        * kjs/string_object.cpp:
        (KJS::StringInstance::indexGetter): Changed to use substr() instead
        of constructing a wholly new UString each time.
        (KJS::stringInstanceNumericPropertyGetter): Added. Like indexGetter, but
        takes advantage of setCustomNumeric to avoid creating an Identifier.
        (KJS::StringInstance::getOwnPropertySlot): Changed to use setCustomNumeric.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27633 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 6a95834c
2007-11-08 Darin Adler <darin@apple.com>
Reviewed by Maciej.
- http://bugs.webkit.org/show_bug.cgi?id=15906
getting characters by indexing into a string is very slow
This fixes one source of the slowness -- the conversion to an unused
Identifier as we call the get function from the slot -- but doesn't
fix others, such as the fact that we have to allocate a new UString::Rep
for every single character.
Speeds up string-base64 30%, and at least 0.5% overall.
But does slow down access-fannkuch quite a bit. Might be worth
revisiting in the future to see what we can do about that (although
I did look at a profile for a while).
* kjs/property_slot.h: Add a new marker for "numeric" property slots;
slots where we don't need to pass the identifier to the get function.
(KJS::PropertySlot::getValue): Added code to call the numeric get function.
(KJS::PropertySlot::setCustomNumeric): Added.
* kjs/string_object.cpp:
(KJS::StringInstance::indexGetter): Changed to use substr() instead
of constructing a wholly new UString each time.
(KJS::stringInstanceNumericPropertyGetter): Added. Like indexGetter, but
takes advantage of setCustomNumeric to avoid creating an Identifier.
(KJS::StringInstance::getOwnPropertySlot): Changed to use setCustomNumeric.
2007-11-08 Darin Adler <darin@apple.com>
Reviewed by Oliver.
......
// -*- c-basic-offset: 4 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 2005 Apple Computer, Inc.
* Copyright (C) 2005, 2007 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -34,57 +33,70 @@ class JSObject;
struct HashEntry;
#define VALUE_SLOT_MARKER ((GetValueFunc)1)
class PropertySlot
{
#define KJS_VALUE_SLOT_MARKER 0
#define KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER reinterpret_cast<GetValueFunc>(1)
class PropertySlot {
public:
typedef JSValue *(*GetValueFunc)(ExecState *, JSObject *originalObject, const Identifier&, const PropertySlot&);
typedef JSValue* (*GetValueFunc)(ExecState*, JSObject* originalObject, const Identifier&, const PropertySlot&);
typedef JSValue* (*GetValueNumericFunc)(ExecState*, JSObject* originalObject, unsigned index, const PropertySlot&);
JSValue *getValue(ExecState *exec, JSObject *originalObject, const Identifier& propertyName) const
JSValue* getValue(ExecState* exec, JSObject* originalObject, const Identifier& propertyName) const
{
if (m_getValue == VALUE_SLOT_MARKER)
if (m_getValue == KJS_VALUE_SLOT_MARKER)
return *m_data.valueSlot;
ASSERT(m_getValue != KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER);
return m_getValue(exec, originalObject, propertyName, *this);
}
JSValue *getValue(ExecState *exec, JSObject *originalObject, unsigned propertyName) const
JSValue* getValue(ExecState* exec, JSObject* originalObject, unsigned propertyName) const
{
if (m_getValue == VALUE_SLOT_MARKER)
if (m_getValue == KJS_VALUE_SLOT_MARKER)
return *m_data.valueSlot;
if (m_getValue == KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER)
return m_data.numericFunc(exec, originalObject, propertyName, *this);
return m_getValue(exec, originalObject, Identifier::from(propertyName), *this);
}
void setValueSlot(JSObject *slotBase, JSValue **valueSlot)
void setValueSlot(JSObject* slotBase, JSValue** valueSlot)
{
m_getValue = KJS_VALUE_SLOT_MARKER;
m_slotBase = slotBase;
m_data.valueSlot = valueSlot;
m_getValue = VALUE_SLOT_MARKER;
}
void setStaticEntry(JSObject *slotBase, const HashEntry *staticEntry, GetValueFunc getValue)
void setStaticEntry(JSObject* slotBase, const HashEntry* staticEntry, GetValueFunc getValue)
{
ASSERT(getValue);
m_getValue = getValue;
m_slotBase = slotBase;
m_data.staticEntry = staticEntry;
m_getValue = getValue;
}
void setCustom(JSObject *slotBase, GetValueFunc getValue)
void setCustom(JSObject* slotBase, GetValueFunc getValue)
{
ASSERT(getValue);
m_slotBase = slotBase;
m_getValue = getValue;
m_slotBase = slotBase;
}
void setCustomIndex(JSObject *slotBase, unsigned index, GetValueFunc getValue)
void setCustomIndex(JSObject* slotBase, unsigned index, GetValueFunc getValue)
{
ASSERT(getValue);
m_getValue = getValue;
m_slotBase = slotBase;
m_data.index = index;
m_getValue = getValue;
}
void setGetterSlot(JSObject *slotBase, JSObject *getterFunc)
void setCustomNumeric(JSObject* slotBase, GetValueNumericFunc getValue)
{
ASSERT(getValue);
m_slotBase = slotBase;
m_getValue = KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER;
m_data.numericFunc = getValue;
}
void setGetterSlot(JSObject* slotBase, JSObject* getterFunc)
{
m_getValue = functionGetter;
m_slotBase = slotBase;
......@@ -97,23 +109,24 @@ public:
m_getValue = undefinedGetter;
}
JSObject *slotBase() const { return m_slotBase; }
JSObject* slotBase() const { return m_slotBase; }
const HashEntry *staticEntry() const { return m_data.staticEntry; }
const HashEntry* staticEntry() const { return m_data.staticEntry; }
unsigned index() const { return m_data.index; }
private:
static JSValue *undefinedGetter(ExecState *, JSObject *, const Identifier&, const PropertySlot&);
static JSValue *functionGetter(ExecState *, JSObject *, const Identifier&, const PropertySlot&);
static JSValue* undefinedGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
static JSValue* functionGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
GetValueFunc m_getValue;
JSObject *m_slotBase;
JSObject* m_slotBase;
union {
JSObject *getterFunc;
JSValue **valueSlot;
const HashEntry *staticEntry;
JSObject* getterFunc;
JSValue** valueSlot;
const HashEntry* staticEntry;
unsigned index;
GetValueNumericFunc numericFunc;
} m_data;
};
......
......@@ -68,10 +68,14 @@ JSValue *StringInstance::lengthGetter(ExecState*, JSObject*, const Identifier&,
return jsNumber(static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().size());
}
JSValue *StringInstance::indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot &slot)
JSValue* StringInstance::indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot)
{
const UChar c = static_cast<StringInstance*>(slot.slotBase())->internalValue()->value()[slot.index()];
return jsString(UString(&c, 1));
return jsString(static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().substr(slot.index(), 1));
}
static JSValue* stringInstanceNumericPropertyGetter(ExecState*, JSObject*, unsigned index, const PropertySlot& slot)
{
return jsString(static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().substr(index, 1));
}
bool StringInstance::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
......@@ -96,7 +100,7 @@ bool StringInstance::getOwnPropertySlot(ExecState* exec, unsigned propertyName,
{
unsigned length = internalValue()->value().size();
if (propertyName < length) {
slot.setCustomIndex(this, propertyName, indexGetter);
slot.setCustomNumeric(this, stringInstanceNumericPropertyGetter);
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment