Changeset 31147 in webkit for trunk/JavaScriptCore/kjs/lookup.cpp
- Timestamp:
- Mar 18, 2008, 9:23:21 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/lookup.cpp
r30942 r31147 1 // -*- c-basic-offset: 2 -*-2 1 /* 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. 5 3 * 6 4 * This library is free software; you can redistribute it and/or … … 23 21 #include "lookup.h" 24 22 25 #include <wtf/Assertions.h>26 27 23 namespace KJS { 28 24 29 static inline bool keysMatch(const UChar* c, unsigned len, const char* s) 25 void HashTable::createTable() const 30 26 { 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; 79 41 } 80 42
Note:
See TracChangeset
for help on using the changeset viewer.