Changeset 28777 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Dec 16, 2007, 2:53:51 PM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin Adler and Maciej Stachowiak.


More refactoring to support global variable optimization.


Changed SymbolTable to use RefPtr<UString::Rep> as its key instead of
UString::Rep*. With globals, the symbol table can outlast the
declaration node for any given symbol, so the symbol table needs to ref
its symbol names.


In support, specialized HashMaps with RefPtr keys to allow lookup
via raw pointer, avoiding refcount churn.


SunSpider reports a .6% speedup (prolly just noise).

  • kjs/JSVariableObject.cpp: (KJS::JSVariableObject::getPropertyNames): Symbol table keys are RefPtrs now.
  • kjs/SymbolTable.h: Modified key traits to match RefPtr. Added a static Rep* for null, which helps compute the deletedValue() trait.
  • wtf/HashMap.h: #include the RefPtr specialization so everyone can use it.
  • wtf/RefPtrHashMap.h: Copied from wtf/HashMap.h. Added overloaded versions of find(), contains(), get(), set(), add(), remove(), and take() that take raw pointers as keys.
Location:
trunk/JavaScriptCore/kjs
Files:
2 edited

Legend:

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

    r28527 r28777  
    3434namespace KJS {
    3535
     36UString::Rep* IdentifierRepHashTraits::nullRepPtr = &UString::Rep::null; // Didn't want to make a whole source file for just this.
     37
    3638bool JSVariableObject::deleteProperty(ExecState* exec, const Identifier& propertyName)
    3739{
     
    4648    SymbolTable::const_iterator::Keys end = symbolTable().end().keys();
    4749    for (SymbolTable::const_iterator::Keys it = symbolTable().begin().keys(); it != end; ++it)
    48         propertyNames.add(Identifier(*it));
     50        propertyNames.add(Identifier(it->get()));
    4951
    5052    JSObject::getPropertyNames(exec, propertyNames);
  • trunk/JavaScriptCore/kjs/SymbolTable.h

    r27198 r28777  
    3030#define SymbolTable_h
    3131
    32 #include "property_map.h"
    33 #include "AlwaysInline.h"
     32#include "ustring.h"
     33#include <wtf/AlwaysInline.h>
    3434
    3535namespace KJS {
    3636
    37     class JSValue;
     37    struct IdentifierRepHash {
     38        static unsigned hash(const RefPtr<UString::Rep>& key) { return key->computedHash(); }
     39        static bool equal(const RefPtr<UString::Rep>& a, const RefPtr<UString::Rep>& b) { return a == b; }
     40        static const bool safeToCompareToEmptyOrDeleted = true;
     41    };
    3842
    39     struct IdentifierRepHash {
    40         static unsigned hash(const KJS::UString::Rep *key) { return key->computedHash(); }
    41         static bool equal(const KJS::UString::Rep *a, const KJS::UString::Rep *b) { return a == b; }
    42         static const bool safeToCompareToEmptyOrDeleted = true;
     43    struct IdentifierRepHashTraits : HashTraits<RefPtr<UString::Rep> > {
     44        static const RefPtr<UString::Rep>& deletedValue()
     45        {
     46            return *reinterpret_cast<RefPtr<UString::Rep>*>(&nullRepPtr);
     47        }
     48
     49    private:
     50        static UString::Rep* nullRepPtr;
    4351    };
    4452
     
    5462    };
    5563
    56     typedef HashMap<UString::Rep*, size_t, IdentifierRepHash, HashTraits<UString::Rep*>, SymbolTableIndexHashTraits> SymbolTable;
     64    typedef HashMap<RefPtr<UString::Rep>, size_t, IdentifierRepHash, IdentifierRepHashTraits, SymbolTableIndexHashTraits> SymbolTable;
    5765
    5866} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.