Changeset 2740 in webkit for trunk/JavaScriptCore
- Timestamp:
- Nov 18, 2002, 3:43:22 PM (23 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r2738 r2740 1 2002-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 1 30 2002-11-18 Darin Adler <[email protected]> 2 31 -
trunk/JavaScriptCore/ChangeLog-2002-12-03
r2738 r2740 1 2002-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 1 30 2002-11-18 Darin Adler <[email protected]> 2 31 -
trunk/JavaScriptCore/ChangeLog-2003-10-25
r2738 r2740 1 2002-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 1 30 2002-11-18 Darin Adler <[email protected]> 2 31 -
trunk/JavaScriptCore/kjs/object.cpp
r2736 r2740 45 45 extern const UString lengthPropertyName("length"); 46 46 extern const UString prototypePropertyName("prototype"); 47 extern const UString specialPrototypePropertyName("__proto__"); 47 48 extern const UString toStringPropertyName("toString"); 48 49 extern const UString valueOfPropertyName("valueOf"); … … 94 95 _proto->mark(); 95 96 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(); 102 98 103 99 if (_internalValue && !_internalValue->marked()) … … 152 148 Value ObjectImp::get(ExecState *exec, const UString &propertyName) const 153 149 { 154 if (propertyName == "__proto__") {155 Object proto = Object::dynamicCast(prototype());156 // non-standard netscape extension157 if (proto.isNull())158 return Null();159 else160 return proto;161 }162 163 150 ValueImp *imp = getDirect(propertyName); 164 151 if ( imp ) … … 168 155 if (proto.isNull()) 169 156 return Undefined(); 157 158 // non-standard netscape extension 159 if (propertyName == specialPrototypePropertyName) 160 return proto; 170 161 171 162 return proto.get(exec,propertyName); … … 205 196 } 206 197 207 if (propertyName == "__proto__") {208 // non-standard netscape extension198 // non-standard netscape extension 199 if (propertyName == specialPrototypePropertyName) { 209 200 setPrototype(value); 210 201 return; … … 223 214 bool ObjectImp::canPut(ExecState *, const UString &propertyName) const 224 215 { 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); 228 220 229 221 // Look in the static hashtable of properties … … 240 232 bool ObjectImp::hasProperty(ExecState *exec, const UString &propertyName) const 241 233 { 242 if (propertyName == "__proto__")243 return true;244 234 if (_prop->get(propertyName)) 245 235 return true; … … 249 239 return true; 250 240 241 // non-standard netscape extension 242 if (propertyName == specialPrototypePropertyName) 243 return true; 244 251 245 // Look in the prototype 252 246 Object proto = Object::dynamicCast(prototype()); … … 262 256 bool ObjectImp::deleteProperty(ExecState */*exec*/, const UString &propertyName) 263 257 { 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)) 267 262 return false; 268 263 _prop->remove(propertyName); … … 406 401 list = static_cast<ObjectImp*>(_proto)->propList(exec,recursive); 407 402 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)); 415 404 416 405 // Add properties from the static hashtable of properties -
trunk/JavaScriptCore/kjs/object.h
r2736 r2740 709 709 extern const UString lengthPropertyName; 710 710 extern const UString prototypePropertyName; 711 extern const UString specialPrototypePropertyName; 711 712 extern const UString toStringPropertyName; 712 713 extern const UString valueOfPropertyName; -
trunk/JavaScriptCore/kjs/property_map.cpp
r1024 r2740 24 24 #include "property_map.h" 25 25 26 #include "object.h" 27 #include "reference_list.h" 28 26 29 #include <string.h> 27 30 #include <assert.h> 28 31 #include <stdio.h> 29 32 30 using namespace KJS; 33 namespace KJS { 31 34 32 35 // ------------------------------ 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 }; 33 61 34 62 void PropertyMapNode::setLeft(PropertyMapNode *newLeft) … … 204 232 } 205 233 234 ValueImp *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 241 void PropertyMap::clear() 242 { 243 clear(0); 244 } 245 246 void 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 256 void 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 206 266 void PropertyMap::clear(PropertyMapNode *node) 207 267 { … … 549 609 updateHeight(b); 550 610 } 611 612 } // namespace KJS -
trunk/JavaScriptCore/kjs/property_map.h
r1024 r2740 30 30 namespace KJS { 31 31 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; 56 34 57 35 /** … … 74 52 void remove(const UString &name); 75 53 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; 76 60 77 void clear(PropertyMapNode *node = 0); 61 private: 62 63 void clear(PropertyMapNode *node); 78 64 void dump(const PropertyMapNode *node = 0, int indent = 0) const; 79 65 void checkTree(const PropertyMapNode *node = 0) const; … … 81 67 PropertyMapNode *getNode(const UString &name) const; 82 68 PropertyMapNode *first() const; 83 84 private:85 69 86 70 PropertyMapNode *remove(PropertyMapNode *node); -
trunk/JavaScriptCore/kjs/ustring.cpp
r2736 r2740 665 665 return (l1 < l2) ? 1 : -1; 666 666 } 667 668 // Algorithm concept from Algorithms in C++, Sedgewick, Program 14.1. 669 int 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 433 433 434 434 int compare(const UString &, const UString &); 435 int hash(const UString &, int hashTableSize); 435 436 436 437 }; // namespace
Note:
See TracChangeset
for help on using the changeset viewer.