Changeset 36429 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Sep 15, 2008, 12:27:14 AM (17 years ago)
Author:
[email protected]
Message:

2008-09-15 Sam Weinig <[email protected]>

Reviewed by Maciej Stachowiak.

Patch for https://bugs.webkit.org/show_bug.cgi?id=20849
Cache property names for getEnumerablePropertyNames in the StructureID.

~0.5% speedup on Sunspider overall (9.7% speedup on string-fasta). ~1% speedup
on the v8 test suite.

  • kjs/JSObject.cpp: (JSC::JSObject::getPropertyNames):
  • kjs/PropertyMap.cpp: (JSC::PropertyMap::getEnumerablePropertyNames):
  • kjs/PropertyMap.h:
  • kjs/StructureID.cpp: (JSC::StructureID::StructureID): (JSC::StructureID::getEnumerablePropertyNames):
  • kjs/StructureID.h:
Location:
trunk/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r36427 r36429  
     12008-09-15  Sam Weinig  <[email protected]>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Patch for https://bugs.webkit.org/show_bug.cgi?id=20849
     6        Cache property names for getEnumerablePropertyNames in the StructureID.
     7
     8        ~0.5% speedup on Sunspider overall (9.7% speedup on string-fasta).  ~1% speedup
     9        on the v8 test suite.
     10
     11        * kjs/JSObject.cpp:
     12        (JSC::JSObject::getPropertyNames):
     13        * kjs/PropertyMap.cpp:
     14        (JSC::PropertyMap::getEnumerablePropertyNames):
     15        * kjs/PropertyMap.h:
     16        * kjs/StructureID.cpp:
     17        (JSC::StructureID::StructureID):
     18        (JSC::StructureID::getEnumerablePropertyNames):
     19        * kjs/StructureID.h:
     20
    1212008-09-14  Maciej Stachowiak  <[email protected]>
    222
  • trunk/JavaScriptCore/kjs/JSObject.cpp

    r36417 r36429  
    433433void JSObject::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
    434434{
    435     m_structureID->propertyMap().getEnumerablePropertyNames(propertyNames);
     435    m_structureID->getEnumerablePropertyNames(propertyNames);
    436436
    437437    // Add properties from the static hashtables of properties
  • trunk/JavaScriptCore/kjs/PropertyMap.cpp

    r36325 r36429  
    2424#include "JSObject.h"
    2525#include "protect.h"
    26 #include "PropertyNameArray.h"
    2726#include <algorithm>
    2827#include <wtf/Assertions.h>
     
    474473}
    475474
    476 void PropertyMap::getEnumerablePropertyNames(PropertyNameArray& propertyNames) const
     475void PropertyMap::getEnumerablePropertyNames(Vector<UString::Rep*>& propertyNames) const
    477476{
    478477    if (!m_table)
     
    493492            }
    494493        }
    495         if (!propertyNames.size()) {
    496             for (int k = 0; k < i; ++k)
    497                 propertyNames.addKnownUnique(a[k]->key);
    498         } else {
    499             for (int k = 0; k < i; ++k)
    500                 propertyNames.add(a[k]->key);
    501         }
     494        propertyNames.reserveCapacity(i);
     495        for (int k = 0; k < i; ++k)
     496            propertyNames.append(a[k]->key);
    502497        return;
    503498    }
     
    518513
    519514    // Put the keys of the sorted entries into the list.
    520     for (Entry** q = sortedEnumerables.data(); q != p; ++q)
    521         propertyNames.add(q[0]->key);
     515    propertyNames.reserveCapacity(sortedEnumerables.size());
     516    for (size_t i = 0; i < sortedEnumerables.size(); ++i)
     517        propertyNames.append(sortedEnumerables[i]->key);
    522518}
    523519
  • trunk/JavaScriptCore/kjs/PropertyMap.h

    r36325 r36429  
    3131    class JSObject;
    3232    class JSValue;
    33     class PropertyNameArray;
    3433
    3534    typedef JSValue** PropertyStorage;
     
    9594        size_t getOffset(const Identifier& propertyName, unsigned& attributes);
    9695
    97         void getEnumerablePropertyNames(PropertyNameArray&) const;
     96        void getEnumerablePropertyNames(Vector<UString::Rep*>&) const;
    9897
    9998        bool hasGetterSetterProperties() const { return m_getterSetterFlag; }
  • trunk/JavaScriptCore/kjs/StructureID.cpp

    r36401 r36429  
    2929#include "identifier.h"
    3030#include "JSObject.h"
     31#include "PropertyNameArray.h";
    3132#include <wtf/RefPtr.h>
    3233
     
    3536namespace JSC {
    3637
    37     StructureID::StructureID(JSValue* prototype, JSType type)
     38StructureID::StructureID(JSValue* prototype, JSType type)
    3839    : m_isDictionary(false)
    3940    , m_type(type)
     
    4647    ASSERT(m_prototype);
    4748    ASSERT(m_prototype->isObject() || m_prototype->isNull());
     49}
     50
     51void StructureID::getEnumerablePropertyNames(PropertyNameArray& propertyNames) const
     52{
     53    if (m_cachedPropertyNameArray.isEmpty())
     54        m_propertyMap.getEnumerablePropertyNames(m_cachedPropertyNameArray);
     55
     56    if (!propertyNames.size()) {
     57        for (size_t i = 0; i < m_cachedPropertyNameArray.size(); ++i)
     58            propertyNames.addKnownUnique(m_cachedPropertyNameArray[i]);
     59    } else {
     60        for (size_t i = 0; i < m_cachedPropertyNameArray.size(); ++i)
     61            propertyNames.add(m_cachedPropertyNameArray[i]);
     62    }
    4863}
    4964
  • trunk/JavaScriptCore/kjs/StructureID.h

    r36401 r36429  
    4040
    4141    class JSValue;
     42    class PropertyNameArray;
    4243    class StructureIDChain;
    4344
     
    108109        PropertyMap& propertyMap() { return m_propertyMap; }
    109110
     111        void getEnumerablePropertyNames(PropertyNameArray&) const;
     112
    110113        static void transitionTo(StructureID* oldStructureID, StructureID* newStructureID, JSObject* slotBase);
    111114
     
    131134        TransitionTable m_transitionTable;
    132135
     136        mutable Vector<UString::Rep*> m_cachedPropertyNameArray;
     137
    133138        PropertyMap m_propertyMap;
    134139    };
Note: See TracChangeset for help on using the changeset viewer.