Changeset 2758 in webkit for trunk/JavaScriptCore/kjs/lookup.cpp


Ignore:
Timestamp:
Nov 19, 2002, 10:59:28 AM (23 years ago)
Author:
darin
Message:
  • 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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/lookup.cpp

    r1024 r2758  
    3131using namespace KJS;
    3232
     33static bool keysMatch(const UChar *c, unsigned len, const char *s)
     34{
     35  for (unsigned i = 0; i != len; i++, c++, s++)
     36    if (c->unicode() != (unsigned char)*s)
     37      return false;
     38  return *s == 0;
     39}
     40
    3341const HashEntry* Lookup::findEntry( const struct HashTable *table,
    3442                              const UChar *c, unsigned int len )
    3543{
     44#ifndef NDEBUG
    3645  if (table->type != 2) {
    3746    fprintf(stderr, "KJS: Unknown hash table version.\n");
    3847    return 0;
    3948  }
    40   char *ascii = new char[len+1];
    41   unsigned int i;
    42   for(i = 0; i < len; i++, c++) {
    43     if (!c->high())
    44       ascii[i] = c->low();
    45     else
    46       break;
    47   }
    48   ascii[i] = '\0';
     49#endif
    4950
    50   int h = hash(ascii) % table->hashSize;
     51  int h = hash(c, len) % table->hashSize;
    5152  const HashEntry *e = &table->entries[h];
    5253
    5354  // empty bucket ?
    54   if (!e->s) {
    55     delete [] ascii;
     55  if (!e->s)
    5656    return 0;
    57   }
    5857
    5958  do {
    6059    // compare strings
    61     if (strcmp(ascii, e->s) == 0) {
    62       delete [] ascii;
     60    if (keysMatch(c, len, e->s))
    6361      return e;
    64     }
    6562    // try next bucket
    6663    e = e->next;
    6764  } while (e);
    6865
    69   delete [] ascii;
    7066  return 0;
    7167}
Note: See TracChangeset for help on using the changeset viewer.