Commit 091be39c authored by darin's avatar darin

- fix hash function and key comparison for the other kind of hash table; yields 3%

        * kjs/lookup.cpp:
        (keysMatch): Added.
        (Lookup::findEntry): Don't allocate and convert to ASCII just to search.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2758 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8091bedc
2002-11-19 Darin Adler <darin@apple.com>
- fix hash function and key comparison for the other kind of hash table; yields 3%
* kjs/lookup.cpp:
(keysMatch): Added.
(Lookup::findEntry): Don't allocate and convert to ASCII just to search.
2002-11-19 Darin Adler <darin@apple.com>
- another hash table fix; yields a 2% improvement on iBench JavaScript
......
2002-11-19 Darin Adler <darin@apple.com>
- fix hash function and key comparison for the other kind of hash table; yields 3%
* kjs/lookup.cpp:
(keysMatch): Added.
(Lookup::findEntry): Don't allocate and convert to ASCII just to search.
2002-11-19 Darin Adler <darin@apple.com>
- another hash table fix; yields a 2% improvement on iBench JavaScript
......
2002-11-19 Darin Adler <darin@apple.com>
- fix hash function and key comparison for the other kind of hash table; yields 3%
* kjs/lookup.cpp:
(keysMatch): Added.
(Lookup::findEntry): Don't allocate and convert to ASCII just to search.
2002-11-19 Darin Adler <darin@apple.com>
- another hash table fix; yields a 2% improvement on iBench JavaScript
......
......@@ -30,43 +30,39 @@
using namespace KJS;
static bool keysMatch(const UChar *c, unsigned len, const char *s)
{
for (unsigned i = 0; i != len; i++, c++, s++)
if (c->unicode() != (unsigned char)*s)
return false;
return *s == 0;
}
const HashEntry* Lookup::findEntry( const struct HashTable *table,
const UChar *c, unsigned int len )
{
#ifndef NDEBUG
if (table->type != 2) {
fprintf(stderr, "KJS: Unknown hash table version.\n");
return 0;
}
char *ascii = new char[len+1];
unsigned int i;
for(i = 0; i < len; i++, c++) {
if (!c->high())
ascii[i] = c->low();
else
break;
}
ascii[i] = '\0';
#endif
int h = hash(ascii) % table->hashSize;
int h = hash(c, len) % table->hashSize;
const HashEntry *e = &table->entries[h];
// empty bucket ?
if (!e->s) {
delete [] ascii;
if (!e->s)
return 0;
}
do {
// compare strings
if (strcmp(ascii, e->s) == 0) {
delete [] ascii;
if (keysMatch(c, len, e->s))
return e;
}
// try next bucket
e = e->next;
} while (e);
delete [] ascii;
return 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment