source:
webkit/trunk/JavaScriptCore/runtime/Lookup.cpp@
40176
Last change on this file since 40176 was 39670, checked in by [email protected], 16 years ago | |
---|---|
2009-01-05 Gavin Barraclough <[email protected]>
JavaScriptGlue:
2009-01-05 Gavin Barraclough <[email protected]>
WebCore:
2009-01-05 Gavin Barraclough <[email protected]>
WebKit/mac:
2009-01-05 Gavin Barraclough <[email protected]>
|
|
|
|
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 | |
25 | namespace JSC { |
26 | |
27 | void 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 | |
67 | void 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 | |
84 | void setUpStaticFunctionSlot(ExecState* exec, const HashEntry* entry, JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot) |
85 | { |
86 | ASSERT(entry->attributes() & Function); |
87 | JSValuePtr* 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 |