Changeset 39056 in webkit for trunk/JavaScriptCore/runtime
- Timestamp:
- Dec 5, 2008, 5:05:06 PM (16 years ago)
- Location:
- trunk/JavaScriptCore/runtime
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/Lookup.cpp
r38137 r39056 27 27 void HashTable::createTable(JSGlobalData* globalData) const 28 28 { 29 #if ENABLE(PERFECT_HASH_SIZE) 29 30 ASSERT(!table); 30 31 HashEntry* entries = new HashEntry[hashSizeMask + 1]; … … 38 39 } 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 40 65 } 41 66 … … 43 68 { 44 69 if (table) { 45 for (int i = 0; i != hashSizeMask + 1; ++i) { 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) { 46 76 if (UString::Rep* key = table[i].key()) 47 77 key->deref(); -
trunk/JavaScriptCore/runtime/Lookup.h
r38528 r39056 31 31 #include <wtf/Assertions.h> 32 32 33 // Set ENABLE_PERFECT_HASH_SIZE to 0 to save memory at the 34 // cost of speed. Test your platform as results may vary. 35 #define ENABLE_PERFECT_HASH_SIZE 1 36 33 37 namespace JSC { 34 38 … … 54 58 m_u.store.value1 = v1; 55 59 m_u.store.value2 = v2; 60 #if !ENABLE(PERFECT_HASH_SIZE) 61 m_next = 0; 62 #endif 56 63 } 57 64 … … 68 75 69 76 intptr_t lexerValue() const { ASSERT(!m_attributes); return m_u.lexer.value; } 77 78 #if !ENABLE(PERFECT_HASH_SIZE) 79 void setNext(HashEntry *next) { m_next = next; } 80 HashEntry* next() const { return m_next; } 81 #endif 70 82 71 83 private: … … 91 103 } lexer; 92 104 } m_u; 105 106 #if !ENABLE(PERFECT_HASH_SIZE) 107 HashEntry* m_next; 108 #endif 93 109 }; 94 110 95 111 struct HashTable { 112 #if ENABLE(PERFECT_HASH_SIZE) 96 113 int hashSizeMask; // Precomputed size for the hash table (minus 1). 114 #else 115 int compactSize; 116 int compactHashSizeMask; 117 #endif 97 118 const HashTableValue* values; // Fixed values generated by script. 98 119 mutable const HashEntry* table; // Table allocated at runtime. … … 128 149 ALWAYS_INLINE const HashEntry* entry(const Identifier& identifier) const 129 150 { 151 #if ENABLE(PERFECT_HASH_SIZE) 130 152 ASSERT(table); 131 153 const HashEntry* entry = &table[identifier.ustring().rep()->computedHash() & hashSizeMask]; … … 133 155 return 0; 134 156 return entry; 157 #else 158 ASSERT(table); 159 160 const HashEntry* entry = &table[identifier.ustring().rep()->computedHash() & compactHashSizeMask]; 161 162 if (!entry->key()) 163 return 0; 164 165 do { 166 if (entry->key() == identifier.ustring().rep()) 167 return entry; 168 entry = entry->next(); 169 } while (entry); 170 171 return 0; 172 #endif 135 173 } 136 174 -
trunk/JavaScriptCore/runtime/Structure.cpp
r38440 r39056 308 308 table->initializeIfNeeded(exec); 309 309 ASSERT(table->table); 310 #if ENABLE(PERFECT_HASH_SIZE) 310 311 int hashSizeMask = table->hashSizeMask; 312 #else 313 int hashSizeMask = table->compactSize - 1; 314 #endif 311 315 const HashEntry* entry = table->table; 312 316 for (int i = 0; i <= hashSizeMask; ++i, ++entry) {
Note:
See TracChangeset
for help on using the changeset viewer.