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


Ignore:
Timestamp:
Jan 6, 2006, 3:51:00 PM (19 years ago)
Author:
mjs
Message:

Reviewed by Darin.

Changes mostly thanks to Maks Orlovich, tweaked a little by me.

  • kjs/create_hash_table: Use the same hash as the one used buy Identifier.
  • kjs/function.cpp: (KJS::FunctionImp::processParameters): Use the new List::copyFrom (KJS::ActivationImp::ActivationImp): track variable while iterating
  • kjs/internal.cpp: (KJS::StringImp::toObject): create StringInstance directly
  • kjs/list.cpp: (KJS::List::copy): implement in terms of copyFrom (KJS::List::copyFrom): more efficient way to copy in another list
  • kjs/list.h:
  • kjs/lookup.cpp: (keysMatch): updated to work with identifier hash (findEntry): ditto (Lookup::findEntry): ditto (Lookup::find): ditto
  • kjs/lookup.h:
File:
1 edited

Legend:

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

    r10701 r11920  
    3434static inline bool keysMatch(const UChar *c, unsigned len, const char *s)
    3535{
    36   for (unsigned i = 0; i != len; i++, c++, s++)
     36  const char* end = s + len;
     37  for (; s != end; c++, s++)
    3738    if (c->uc != (unsigned char)*s)
    3839      return false;
     
    4041}
    4142
    42 const HashEntry* Lookup::findEntry( const struct HashTable *table,
    43                               const UChar *c, unsigned int len )
     43static inline const HashEntry* findEntry(const struct HashTable *table, unsigned int hash,
     44                                         const UChar *c, unsigned int len )
    4445{
    4546#ifndef NDEBUG
     
    4950  }
    5051#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];
    5454
    5555  // empty bucket ?
     
    6161    if (keysMatch(c, len, e->s))
    6262      return e;
     63
    6364    // try next bucket
    6465    e = e->next;
    6566  } while (e);
    66 
    6767  return 0;
    6868}
    6969
    70 const HashEntry* Lookup::findEntry( const struct HashTable *table,
    71                                 const Identifier &s )
     70const HashEntry* Lookup::findEntry(const struct HashTable *table,
     71                                   const Identifier &s )
    7272{
    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;
    7475}
    7576
     
    7778                 const UChar *c, unsigned int len)
    7879{
    79   const HashEntry *entry = findEntry( table, c, len );
     80  const HashEntry *entry = ::findEntry(table, UString::Rep::computeHash(c, len), c, len);
    8081  if (entry)
    8182    return entry->value;
     
    8586int Lookup::find(const struct HashTable *table, const Identifier &s)
    8687{
    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;
    8893}
    89 
    90 unsigned int Lookup::hash(const UChar *c, unsigned int len)
    91 {
    92   unsigned int val = 0;
    93   // ignoring higher byte
    94   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.