Changeset 31147 in webkit for trunk/JavaScriptCore/kjs/lookup.cpp


Ignore:
Timestamp:
Mar 18, 2008, 9:23:21 PM (17 years ago)
Author:
Darin Adler
Message:

JavaScriptCore:

2008-03-18 Darin Adler <Darin Adler>

Reviewed by Maciej.

  • Speed up JavaScript built-in properties by changing the hash table to take advantage of the identifier objects

5% speedup for Acid3 test 26

  • JavaScriptCore.exp: Updated.
  • kjs/create_hash_table: Compute size of hash table large enough so that there are no collisions, but don't generate the hash table.
  • kjs/identifier.h: Made the add function that returns a PassRefPtr public.
  • kjs/lexer.cpp: (KJS::Lexer::lex): Updated for change to HashTable interface.
  • kjs/lookup.cpp: (KJS::HashTable::changeKeysToIdentifiers): Added. Finds the identifier for each property so the equality comparision can be done with pointer comparision.
  • kjs/lookup.h: Made the key be a union of char* with UString::Rep* so it can hold identifiers. Added a keysAreIdentifiers flag to the HashTable. Changed the Lookup functions to be member functions of HashTable instead.
  • kjs/object.cpp: (KJS::JSObject::deleteProperty): Update for change to HashTable. (KJS::JSObject::findPropertyHashEntry): Ditto. (KJS::JSObject::getPropertyAttributes): Ditto. (KJS::JSObject::getPropertyNames): Ditto.

WebCore:

2008-03-18 Darin Adler <Darin Adler>

Reviewed by Maciej.

  • Speed up JavaScript built-in properties by changing the hash table to take advantage of the identifier objects

5% speedup for Acid3 test 26

  • bindings/js/JSDOMWindowBase.cpp: (WebCore::JSDOMWindowBase::getOwnPropertySlot): Update for change to HashTable. (WebCore::JSDOMWindowBase::put): Ditto.
  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::JSDOMWindow::customGetOwnPropertySlot): Ditto.
  • bindings/js/JSHTMLInputElementBase.cpp: (WebCore::JSHTMLInputElementBase::getOwnPropertySlot): Ditto.
  • bindings/js/JSHistoryCustom.cpp: (WebCore::JSHistory::customGetOwnPropertySlot): Ditto.
  • bindings/js/JSLocation.cpp: (WebCore::JSLocation::customGetOwnPropertySlot): Ditto. (WebCore::JSLocation::put): Ditto.
  • bindings/js/kjs_binding.cpp: (WebCore::nonCachingStaticFunctionGetter): Ditto.
  • bindings/scripts/CodeGeneratorJS.pm: Same changes as in the create_hash_table script.
File:
1 edited

Legend:

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

    r30942 r31147  
    1 // -*- c-basic-offset: 2 -*-
    21/*
    3  *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    4  *  Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
     2 *  Copyright (C) 2008 Apple Inc. All rights reserved.
    53 *
    64 *  This library is free software; you can redistribute it and/or
     
    2321#include "lookup.h"
    2422
    25 #include <wtf/Assertions.h>
    26 
    2723namespace KJS {
    2824
    29 static inline bool keysMatch(const UChar* c, unsigned len, const char* s)
     25void HashTable::createTable() const
    3026{
    31   // FIXME: This can run off the end of |s| if |c| has a U+0000 character in it.
    32   const char* end = s + len;
    33   for (; s != end; c++, s++)
    34     if (*c != *s)
    35       return false;
    36   return *s == 0;
    37 }
    38 
    39 static inline const HashEntry* findEntry(const struct HashTable* table, unsigned int hash,
    40                                          const UChar* c, unsigned int len)
    41 {
    42   ASSERT(table->type == 3);
    43    
    44   const HashEntry* e = &table->entries[hash & table->hashSizeMask];
    45 
    46   if (!e->s)
    47     return 0;
    48 
    49   do {
    50     // compare strings
    51     if (keysMatch(c, len, e->s))
    52       return e;
    53 
    54     // try next bucket
    55     e = e->next;
    56   } while (e);
    57   return 0;
    58 }
    59 
    60 const HashEntry* Lookup::findEntry(const struct HashTable* table, const Identifier& s)
    61 {
    62   return KJS::findEntry(table, s.ustring().rep()->computedHash(), s.data(), s.size());
    63 }
    64 
    65 int Lookup::find(const struct HashTable *table, const UChar *c, unsigned int len)
    66 {
    67   const HashEntry *entry = KJS::findEntry(table, UString::Rep::computeHash(c, len), c, len);
    68   if (entry)
    69     return entry->value.intValue;
    70   return -1;
    71 }
    72 
    73 int Lookup::find(const struct HashTable* table, const Identifier& s)
    74 {
    75   const HashEntry* entry = KJS::findEntry(table, s.ustring().rep()->computedHash(), s.data(), s.size());
    76   if (entry)
    77     return entry->value.intValue;
    78   return -1;
     27    ASSERT(!table);
     28    HashEntry* entries = new HashEntry[hashSizeMask + 1];
     29    for (int i = 0; i <= hashSizeMask; ++i)
     30        entries[i].key = 0;
     31    for (int i = 0; values[i].key; ++i) {
     32        UString::Rep* identifier = Identifier::add(values[i].key).releaseRef();
     33        int hashIndex = identifier->computedHash() & hashSizeMask;
     34        ASSERT(!entries[hashIndex].key);
     35        entries[hashIndex].key = identifier;
     36        entries[hashIndex].integerValue = values[i].value;
     37        entries[hashIndex].attributes = values[i].attributes;
     38        entries[hashIndex].length = values[i].length;
     39    }
     40    table = entries;
    7941}
    8042
Note: See TracChangeset for help on using the changeset viewer.