Changeset 11920 in webkit for trunk/JavaScriptCore/kjs/lookup.cpp
- Timestamp:
- Jan 6, 2006, 3:51:00 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/lookup.cpp
r10701 r11920 34 34 static inline bool keysMatch(const UChar *c, unsigned len, const char *s) 35 35 { 36 for (unsigned i = 0; i != len; i++, c++, s++) 36 const char* end = s + len; 37 for (; s != end; c++, s++) 37 38 if (c->uc != (unsigned char)*s) 38 39 return false; … … 40 41 } 41 42 42 const HashEntry* Lookup::findEntry( const struct HashTable *table,43 const UChar *c, unsigned int len )43 static inline const HashEntry* findEntry(const struct HashTable *table, unsigned int hash, 44 const UChar *c, unsigned int len ) 44 45 { 45 46 #ifndef NDEBUG … … 49 50 } 50 51 #endif 51 52 int h = hash(c, len) % table->hashSize; 53 const HashEntry *e = &table->entries[h]; 52 hash %= table->hashSize; 53 const HashEntry *e = &table->entries[hash]; 54 54 55 55 // empty bucket ? … … 61 61 if (keysMatch(c, len, e->s)) 62 62 return e; 63 63 64 // try next bucket 64 65 e = e->next; 65 66 } while (e); 66 67 67 return 0; 68 68 } 69 69 70 const HashEntry* Lookup::findEntry( 71 const Identifier &s )70 const HashEntry* Lookup::findEntry(const struct HashTable *table, 71 const Identifier &s ) 72 72 { 73 return findEntry( table, s.data(), s.size() ); 73 const HashEntry* entry = ::findEntry(table, s.ustring().rep()->hash(), s.data(), s.size()); 74 return entry; 74 75 } 75 76 … … 77 78 const UChar *c, unsigned int len) 78 79 { 79 const HashEntry *entry = findEntry( table, c, len);80 const HashEntry *entry = ::findEntry(table, UString::Rep::computeHash(c, len), c, len); 80 81 if (entry) 81 82 return entry->value; … … 85 86 int Lookup::find(const struct HashTable *table, const Identifier &s) 86 87 { 87 return find(table, s.data(), s.size()); 88 //printf("looking for:%s\n", s.ascii()); 89 const HashEntry *entry = ::findEntry(table, s.ustring().rep()->hash(), s.data(), s.size()); 90 if (entry) 91 return entry->value; 92 return -1; 88 93 } 89 90 unsigned int Lookup::hash(const UChar *c, unsigned int len)91 {92 unsigned int val = 0;93 // ignoring higher byte94 for (unsigned int i = 0; i < len; i++, c++)95 val += c->low();96 97 return val;98 }99 100 unsigned int Lookup::hash(const Identifier &key)101 {102 return hash(key.data(), key.size());103 }104 105 unsigned int Lookup::hash(const char *s)106 {107 unsigned int val = 0;108 while (*s)109 val += *s++;110 111 return val;112 }
Note:
See TracChangeset
for help on using the changeset viewer.