Changeset 2740 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp


Ignore:
Timestamp:
Nov 18, 2002, 3:43:22 PM (23 years ago)
Author:
darin
Message:
  • another string constant discovered that can be optimized
  • kjs/object.h: Add a property name constant for "proto".
  • kjs/object.cpp: Define it. (ObjectImp::get): Use it. (ObjectImp::hasProperty): Use it.
  • prepare to turn PropertyMap into a hash table
  • kjs/object.cpp: (ObjectImp::mark): Use the new PropertyMap::mark(). (ObjectImp::put): Use the new overload of PropertyMap::get(). (ObjectImp::deleteProperty): Use the new overload of PropertyMap::get(). (ObjectImp::propList): Use PropertyMap::addEnumerablesToReferenceList().
  • kjs/property_map.h: Remove PropertyMapNode and make all node-related methods private. Add mark(), a new overload of get() that returns attributes, a clear() that takes no attributes, and addEnumerablesToReferenceList().
  • kjs/property_map.cpp: (PropertyMap::get): Added new overload. (PropertyMap::clear): Added new overload. (PropertyMap::mark): Added. (PropertyMap::addEnumerablesToReferenceList): Added.
  • kjs/ustring.h: Added a hash function.
  • kjs/ustring.cpp: (KJS::hash): Added.
File:
1 edited

Legend:

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

    r2736 r2740  
    665665  return (l1 < l2) ? 1 : -1;
    666666}
     667
     668// Algorithm concept from Algorithms in C++, Sedgewick, Program 14.1.
     669int KJS::hash(const UString &s, int hashTableSize)
     670{
     671    int h = 0;
     672    int length = s.size();
     673    int prefix = length < 8 ? length : 8;
     674    for (int i = 0; i != prefix; i++)
     675        h = (127 * h + s[i].unicode()) % hashTableSize;
     676    int suffix = length < 16 ? 8 : length - 8;
     677    for (int i = suffix; i != length; i++)
     678        h = (127 * h + s[i].unicode()) % hashTableSize;
     679    return h;
     680}
Note: See TracChangeset for help on using the changeset viewer.