#include "config.h"
#include "lookup.h"
#include <wtf/Assertions.h>
namespace KJS {
static inline bool keysMatch(const UChar* c, unsigned len, const char* s)
{
const char* end = s + len;
for (; s != end; c++, s++)
if (c->uc != *s)
return false;
return *s == 0;
}
static inline const HashEntry* findEntry(const struct HashTable* table, unsigned int hash,
const UChar* c, unsigned int len)
{
ASSERT(table->type == 3);
const HashEntry* e = &table->entries[hash & table->hashSizeMask];
if (!e->s)
return 0;
do {
if (keysMatch(c, len, e->s))
return e;
e = e->next;
} while (e);
return 0;
}
const HashEntry* Lookup::findEntry(const struct HashTable* table, const Identifier& s)
{
return KJS::findEntry(table, s.ustring().rep()->computedHash(), s.data(), s.size());
}
int Lookup::find(const struct HashTable *table, const UChar *c, unsigned int len)
{
const HashEntry *entry = KJS::findEntry(table, UString::Rep::computeHash(c, len), c, len);
if (entry)
return entry->value.intValue;
return -1;
}
int Lookup::find(const struct HashTable* table, const Identifier& s)
{
const HashEntry* entry = KJS::findEntry(table, s.ustring().rep()->computedHash(), s.data(), s.size());
if (entry)
return entry->value.intValue;
return -1;
}
}