Changeset 2740 in webkit for trunk/JavaScriptCore


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.
Location:
trunk/JavaScriptCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r2738 r2740  
     12002-11-18  Darin Adler  <[email protected]>
     2
     3        - another string constant discovered that can be optimized
     4
     5        * kjs/object.h: Add a property name constant for "__proto__".
     6        * kjs/object.cpp: Define it.
     7        (ObjectImp::get): Use it.
     8        (ObjectImp::hasProperty): Use it.
     9
     10        - prepare to turn PropertyMap into a hash table
     11
     12        * kjs/object.cpp:
     13        (ObjectImp::mark): Use the new PropertyMap::mark().
     14        (ObjectImp::put): Use the new overload of PropertyMap::get().
     15        (ObjectImp::deleteProperty): Use the new overload of PropertyMap::get().
     16        (ObjectImp::propList): Use PropertyMap::addEnumerablesToReferenceList().
     17
     18        * kjs/property_map.h: Remove PropertyMapNode and make all node-related methods private.
     19        Add mark(), a new overload of get() that returns attributes, a clear() that takes no attributes,
     20        and addEnumerablesToReferenceList().
     21        * kjs/property_map.cpp:
     22        (PropertyMap::get): Added new overload.
     23        (PropertyMap::clear): Added new overload.
     24        (PropertyMap::mark): Added.
     25        (PropertyMap::addEnumerablesToReferenceList): Added.
     26
     27        * kjs/ustring.h: Added a hash function.
     28        * kjs/ustring.cpp: (KJS::hash): Added.
     29
    1302002-11-18  Darin Adler  <[email protected]>
    231
  • trunk/JavaScriptCore/ChangeLog-2002-12-03

    r2738 r2740  
     12002-11-18  Darin Adler  <[email protected]>
     2
     3        - another string constant discovered that can be optimized
     4
     5        * kjs/object.h: Add a property name constant for "__proto__".
     6        * kjs/object.cpp: Define it.
     7        (ObjectImp::get): Use it.
     8        (ObjectImp::hasProperty): Use it.
     9
     10        - prepare to turn PropertyMap into a hash table
     11
     12        * kjs/object.cpp:
     13        (ObjectImp::mark): Use the new PropertyMap::mark().
     14        (ObjectImp::put): Use the new overload of PropertyMap::get().
     15        (ObjectImp::deleteProperty): Use the new overload of PropertyMap::get().
     16        (ObjectImp::propList): Use PropertyMap::addEnumerablesToReferenceList().
     17
     18        * kjs/property_map.h: Remove PropertyMapNode and make all node-related methods private.
     19        Add mark(), a new overload of get() that returns attributes, a clear() that takes no attributes,
     20        and addEnumerablesToReferenceList().
     21        * kjs/property_map.cpp:
     22        (PropertyMap::get): Added new overload.
     23        (PropertyMap::clear): Added new overload.
     24        (PropertyMap::mark): Added.
     25        (PropertyMap::addEnumerablesToReferenceList): Added.
     26
     27        * kjs/ustring.h: Added a hash function.
     28        * kjs/ustring.cpp: (KJS::hash): Added.
     29
    1302002-11-18  Darin Adler  <[email protected]>
    231
  • trunk/JavaScriptCore/ChangeLog-2003-10-25

    r2738 r2740  
     12002-11-18  Darin Adler  <[email protected]>
     2
     3        - another string constant discovered that can be optimized
     4
     5        * kjs/object.h: Add a property name constant for "__proto__".
     6        * kjs/object.cpp: Define it.
     7        (ObjectImp::get): Use it.
     8        (ObjectImp::hasProperty): Use it.
     9
     10        - prepare to turn PropertyMap into a hash table
     11
     12        * kjs/object.cpp:
     13        (ObjectImp::mark): Use the new PropertyMap::mark().
     14        (ObjectImp::put): Use the new overload of PropertyMap::get().
     15        (ObjectImp::deleteProperty): Use the new overload of PropertyMap::get().
     16        (ObjectImp::propList): Use PropertyMap::addEnumerablesToReferenceList().
     17
     18        * kjs/property_map.h: Remove PropertyMapNode and make all node-related methods private.
     19        Add mark(), a new overload of get() that returns attributes, a clear() that takes no attributes,
     20        and addEnumerablesToReferenceList().
     21        * kjs/property_map.cpp:
     22        (PropertyMap::get): Added new overload.
     23        (PropertyMap::clear): Added new overload.
     24        (PropertyMap::mark): Added.
     25        (PropertyMap::addEnumerablesToReferenceList): Added.
     26
     27        * kjs/ustring.h: Added a hash function.
     28        * kjs/ustring.cpp: (KJS::hash): Added.
     29
    1302002-11-18  Darin Adler  <[email protected]>
    231
  • trunk/JavaScriptCore/kjs/object.cpp

    r2736 r2740  
    4545extern const UString lengthPropertyName("length");
    4646extern const UString prototypePropertyName("prototype");
     47extern const UString specialPrototypePropertyName("__proto__");
    4748extern const UString toStringPropertyName("toString");
    4849extern const UString valueOfPropertyName("valueOf");
     
    9495    _proto->mark();
    9596
    96   PropertyMapNode *node = _prop->first();
    97   while (node) {
    98     if (!node->value->marked())
    99       node->value->mark();
    100     node = node->next();
    101   }
     97  _prop->mark();
    10298
    10399  if (_internalValue && !_internalValue->marked())
     
    152148Value ObjectImp::get(ExecState *exec, const UString &propertyName) const
    153149{
    154   if (propertyName == "__proto__") {
    155     Object proto = Object::dynamicCast(prototype());
    156     // non-standard netscape extension
    157     if (proto.isNull())
    158       return Null();
    159     else
    160       return proto;
    161   }
    162 
    163150  ValueImp *imp = getDirect(propertyName);
    164151  if ( imp )
     
    168155  if (proto.isNull())
    169156    return Undefined();
     157
     158  // non-standard netscape extension
     159  if (propertyName == specialPrototypePropertyName)
     160    return proto;
    170161
    171162  return proto.get(exec,propertyName);
     
    205196  }
    206197
    207   if (propertyName == "__proto__") {
    208     // non-standard netscape extension
     198  // non-standard netscape extension
     199  if (propertyName == specialPrototypePropertyName) {
    209200    setPrototype(value);
    210201    return;
     
    223214bool ObjectImp::canPut(ExecState *, const UString &propertyName) const
    224215{
    225   PropertyMapNode *node = _prop->getNode(propertyName);
    226   if (node)
    227     return!(node->attr & ReadOnly);
     216  int attributes;
     217  ValueImp *v = _prop->get(propertyName, attributes);
     218  if (v)
     219    return!(attributes & ReadOnly);
    228220
    229221  // Look in the static hashtable of properties
     
    240232bool ObjectImp::hasProperty(ExecState *exec, const UString &propertyName) const
    241233{
    242   if (propertyName == "__proto__")
    243     return true;
    244234  if (_prop->get(propertyName))
    245235    return true;
     
    249239      return true;
    250240
     241  // non-standard netscape extension
     242  if (propertyName == specialPrototypePropertyName)
     243    return true;
     244
    251245  // Look in the prototype
    252246  Object proto = Object::dynamicCast(prototype());
     
    262256bool ObjectImp::deleteProperty(ExecState */*exec*/, const UString &propertyName)
    263257{
    264   PropertyMapNode *node = _prop->getNode(propertyName);
    265   if (node) {
    266     if ((node->attr & DontDelete))
     258  int attributes;
     259  ValueImp *v = _prop->get(propertyName, attributes);
     260  if (v) {
     261    if ((attributes & DontDelete))
    267262      return false;
    268263    _prop->remove(propertyName);
     
    406401    list = static_cast<ObjectImp*>(_proto)->propList(exec,recursive);
    407402
    408 
    409   PropertyMapNode *node = _prop->first();
    410   while (node) {
    411     if (!(node->attr & DontEnum))
    412       list.append(Reference(Object(this), node->name));
    413     node = node->next();
    414   }
     403  _prop->addEnumerablesToReferenceList(list, Object(this));
    415404
    416405  // Add properties from the static hashtable of properties
  • trunk/JavaScriptCore/kjs/object.h

    r2736 r2740  
    709709  extern const UString lengthPropertyName;
    710710  extern const UString prototypePropertyName;
     711  extern const UString specialPrototypePropertyName;
    711712  extern const UString toStringPropertyName;
    712713  extern const UString valueOfPropertyName;
  • trunk/JavaScriptCore/kjs/property_map.cpp

    r1024 r2740  
    2424#include "property_map.h"
    2525
     26#include "object.h"
     27#include "reference_list.h"
     28
    2629#include <string.h>
    2730#include <assert.h>
    2831#include <stdio.h>
    2932
    30 using namespace KJS;
     33namespace KJS {
    3134
    3235// ------------------------------ PropertyMapNode ------------------------------
     36
     37  class PropertyMapNode {
     38  public:
     39    PropertyMapNode(const UString &n, ValueImp *v, int att, PropertyMapNode *p)
     40      : name(n), value(v), attr(att), left(0), right(0), parent(p), height(1) {}
     41
     42    UString name;
     43    ValueImp *value;
     44    int attr;
     45
     46    void setLeft(PropertyMapNode *newLeft);
     47    void setRight(PropertyMapNode *newRight);
     48    PropertyMapNode *findMax();
     49    PropertyMapNode *findMin();
     50
     51    PropertyMapNode *next();
     52
     53    PropertyMapNode *left;
     54    PropertyMapNode *right;
     55    PropertyMapNode *parent;
     56    int height;
     57
     58  private:
     59    void setParent(PropertyMapNode *newParent);
     60  };
    3361
    3462void PropertyMapNode::setLeft(PropertyMapNode *newLeft)
     
    204232}
    205233
     234ValueImp *PropertyMap::get(const UString &name, int &attributes) const
     235{
     236  const PropertyMapNode *n = getNode(name);
     237  attributes = n ? n->attr : 0;
     238  return n ? n->value : 0;
     239}
     240
     241void PropertyMap::clear()
     242{
     243  clear(0);
     244}
     245
     246void PropertyMap::mark()
     247{
     248  PropertyMapNode *node = first();
     249  while (node) {
     250    if (!node->value->marked())
     251      node->value->mark();
     252    node = node->next();
     253  }
     254}
     255
     256void PropertyMap::addEnumerablesToReferenceList(ReferenceList &list, const Object &base) const
     257{
     258  PropertyMapNode *node = first();
     259  while (node) {
     260    if (!(node->attr & DontEnum))
     261      list.append(Reference(base, node->name));
     262    node = node->next();
     263  }
     264}
     265
    206266void PropertyMap::clear(PropertyMapNode *node)
    207267{
     
    549609  updateHeight(b);
    550610}
     611
     612} // namespace KJS
  • trunk/JavaScriptCore/kjs/property_map.h

    r1024 r2740  
    3030namespace KJS {
    3131
    32   class PropertyMapNode {
    33   public:
    34     PropertyMapNode(const UString &n, ValueImp *v, int att, PropertyMapNode *p)
    35       : name(n), value(v), attr(att), left(0), right(0), parent(p), height(1) {}
    36 
    37     UString name;
    38     ValueImp *value;
    39     int attr;
    40 
    41     void setLeft(PropertyMapNode *newLeft);
    42     void setRight(PropertyMapNode *newRight);
    43     PropertyMapNode *findMax();
    44     PropertyMapNode *findMin();
    45 
    46     PropertyMapNode *next();
    47 
    48     PropertyMapNode *left;
    49     PropertyMapNode *right;
    50     PropertyMapNode *parent;
    51     int height;
    52 
    53   private:
    54     void setParent(PropertyMapNode *newParent);
    55   };
     32  class PropertyMapNode;
     33  class ReferenceList;
    5634
    5735  /**
     
    7452    void remove(const UString &name);
    7553    ValueImp *get(const UString &name) const;
     54    ValueImp *get(const UString &name, int &attributes) const;
     55   
     56    void clear();
     57    void mark();
     58   
     59    void addEnumerablesToReferenceList(ReferenceList &, const Object &) const;
    7660
    77     void clear(PropertyMapNode *node = 0);
     61  private:
     62
     63    void clear(PropertyMapNode *node);
    7864    void dump(const PropertyMapNode *node = 0, int indent = 0) const;
    7965    void checkTree(const PropertyMapNode *node = 0) const;
     
    8167    PropertyMapNode *getNode(const UString &name) const;
    8268    PropertyMapNode *first() const;
    83 
    84   private:
    8569
    8670    PropertyMapNode *remove(PropertyMapNode *node);
  • 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}
  • trunk/JavaScriptCore/kjs/ustring.h

    r2736 r2740  
    433433 
    434434  int compare(const UString &, const UString &);
     435  int hash(const UString &, int hashTableSize);
    435436
    436437}; // namespace
Note: See TracChangeset for help on using the changeset viewer.