source: webkit/trunk/JavaScriptCore/runtime/Lookup.cpp@ 39571

Last change on this file since 39571 was 39056, checked in by [email protected], 16 years ago

<rdar://problem/6331749> Provide a mechanism to disable perfect hashing in the DOM at build time

Reviewed by Darin Adler.

Initial patch by Yosen Lin. Adapted for ToT WebKit by David Kilzer.

Added back the code that generates a "compact" hash (instead of a
perfect hash) as a build-time option using the
ENABLE(PERFECT_HASH_SIZE) macro as defined in Lookup.h.

JavaScriptCore:

  • create_hash_table: Rename variables to differentiate perfect hash values from compact hash values. Added back code to compute compact hash tables. Generate both hash table sizes and emit conditionalized code based on ENABLE(PERFECT_HASH_SIZE).
  • runtime/Lookup.cpp: (JSC::HashTable::createTable): Added version of createTable() for use with compact hash tables. (JSC::HashTable::deleteTable): Updated to work with compact hash tables.
  • runtime/Lookup.h: Defined ENABLE(PERFECT_HASH_SIZE) macro here. (JSC::HashEntry::initialize): Set m_next to zero when using compact hash tables. (JSC::HashEntry::setNext): Added for compact hash tables. (JSC::HashEntry::next): Added for compact hash tables. (JSC::HashTable::entry): Added version of entry() for use with compact hash tables.
  • runtime/Structure.cpp: (JSC::Structure::getEnumerablePropertyNames): Updated to work with compact hash tables.

WebCore:

  • bindings/scripts/CodeGeneratorJS.pm: (GenerateImplementation): Compute the number of elements that will be stored in each hash table and pass it to GenerateHashTable(). (GenerateHashTable): Added new second parameter representing the number of elements to store in the compact hash table. Added back code to compute compact hash tables. Generate both hash table sizes and emit conditionalized code based on ENABLE(PERFECT_HASH_SIZE).
  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 */
19
20#include "config.h"
21#include "Lookup.h"
22
23#include "PrototypeFunction.h"
24
25namespace JSC {
26
27void HashTable::createTable(JSGlobalData* globalData) const
28{
29#if ENABLE(PERFECT_HASH_SIZE)
30 ASSERT(!table);
31 HashEntry* entries = new HashEntry[hashSizeMask + 1];
32 for (int i = 0; i <= hashSizeMask; ++i)
33 entries[i].setKey(0);
34 for (int i = 0; values[i].key; ++i) {
35 UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
36 int hashIndex = identifier->computedHash() & hashSizeMask;
37 ASSERT(!entries[hashIndex].key());
38 entries[hashIndex].initialize(identifier, values[i].attributes, values[i].value1, values[i].value2);
39 }
40 table = entries;
41#else
42 ASSERT(!table);
43 int linkIndex = compactHashSizeMask + 1;
44 HashEntry* entries = new HashEntry[compactSize];
45 for (int i = 0; i < compactSize; ++i)
46 entries[i].setKey(0);
47 for (int i = 0; values[i].key; ++i) {
48 UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
49 int hashIndex = identifier->computedHash() & compactHashSizeMask;
50 HashEntry* entry = &entries[hashIndex];
51
52 if (entry->key()) {
53 while (entry->next()) {
54 entry = entry->next();
55 }
56 ASSERT(linkIndex < compactSize);
57 entry->setNext(&entries[linkIndex++]);
58 entry = entry->next();
59 }
60
61 entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2);
62 }
63 table = entries;
64#endif
65}
66
67void HashTable::deleteTable() const
68{
69 if (table) {
70#if ENABLE(PERFECT_HASH_SIZE)
71 int max = hashSizeMask + 1;
72#else
73 int max = compactSize;
74#endif
75 for (int i = 0; i != max; ++i) {
76 if (UString::Rep* key = table[i].key())
77 key->deref();
78 }
79 delete [] table;
80 table = 0;
81 }
82}
83
84void setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot)
85{
86 ASSERT(entry->attributes() & Function);
87 JSValue** location = thisObj->getDirectLocation(propertyName);
88
89 if (!location) {
90 PrototypeFunction* function = new (exec) PrototypeFunction(exec, entry->functionLength(), propertyName, entry->function());
91 thisObj->putDirect(propertyName, function, entry->attributes());
92 location = thisObj->getDirectLocation(propertyName);
93 }
94
95 slot.setValueSlot(thisObj, location, thisObj->offsetForLocation(location));
96}
97
98} // namespace JSC
Note: See TracBrowser for help on using the repository browser.