Changeset 38016 in webkit for trunk/JavaScriptCore/runtime/StructureID.h
- Timestamp:
- Oct 30, 2008, 5:12:50 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/StructureID.h
r37989 r38016 1 // -*- mode: c++; c-basic-offset: 4 -*-2 1 /* 3 2 * Copyright (C) 2008 Apple Inc. All rights reserved. … … 30 29 #include "JSType.h" 31 30 #include "JSValue.h" 32 #include "PropertyMap .h"31 #include "PropertyMapHashTable.h" 33 32 #include "StructureIDTransitionTable.h" 34 33 #include "TypeInfo.h" 34 #include "identifier.h" 35 35 #include "ustring.h" 36 36 #include <wtf/HashFunctions.h> … … 41 41 42 42 #define DUMP_STRUCTURE_ID_STATISTICS 0 43 44 #ifndef NDEBUG 45 #define DUMP_PROPERTYMAP_STATS 0 46 #else 47 #define DUMP_PROPERTYMAP_STATS 0 48 #endif 43 49 44 50 namespace JSC { … … 65 71 static PassRefPtr<StructureID> changePrototypeTransition(StructureID*, JSValue* prototype); 66 72 static PassRefPtr<StructureID> addPropertyTransition(StructureID*, const Identifier& propertyName, unsigned attributes, size_t& offset); 73 static PassRefPtr<StructureID> removePropertyTransition(StructureID*, const Identifier& propertyName, size_t& offset); 67 74 static PassRefPtr<StructureID> getterSetterTransition(StructureID*); 68 75 static PassRefPtr<StructureID> toDictionaryTransition(StructureID*); … … 79 86 // These should be used with caution. 80 87 size_t addPropertyWithoutTransition(const Identifier& propertyName, unsigned attributes); 88 size_t removePropertyWithoutTransition(const Identifier& propertyName); 81 89 void setPrototypeWithoutTransition(JSValue* prototype) { m_prototype = prototype; } 82 90 … … 102 110 void growPropertyStorageCapacity(); 103 111 size_t propertyStorageCapacity() const { return m_propertyStorageCapacity; } 104 size_t propertyStorageSize() const { return m_propertyMap.storageSize(); } 105 106 size_t get(const Identifier& propertyName) const { return m_propertyMap.get(propertyName); } 107 size_t get(const Identifier& propertyName, unsigned& attributes) const { return m_propertyMap.get(propertyName, attributes); } 108 size_t put(const Identifier& propertyName, unsigned attributes) { return m_propertyMap.put(propertyName, attributes); } 109 size_t remove(const Identifier& propertyName) { return m_propertyMap.remove(propertyName); } 110 112 size_t propertyStorageSize() const { return m_propertyTable ? m_propertyTable->keyCount + m_deletedOffsets.size() : 0; } 113 114 size_t get(const Identifier& propertyName) const; 115 size_t get(const Identifier& propertyName, unsigned& attributes) const; 111 116 void getEnumerablePropertyNames(ExecState*, PropertyNameArray&, JSObject*); 112 void clearEnumerationCache();113 117 114 118 bool hasGetterSetterProperties() const { return m_hasGetterSetterProperties; } 115 119 void setHasGetterSetterProperties(bool hasGetterSetterProperties) { m_hasGetterSetterProperties = hasGetterSetterProperties; } 116 120 117 bool isEmpty() const { return m_propertyMap.isEmpty(); }121 bool isEmpty() const { return !m_propertyTable; } 118 122 119 123 private: 120 124 StructureID(JSValue* prototype, const TypeInfo&); 121 125 126 size_t put(const Identifier& propertyName, unsigned attributes); 127 size_t remove(const Identifier& propertyName); 128 void getEnumerablePropertyNamesInternal(PropertyNameArray&) const; 129 130 void expandPropertyMapHashTable(); 131 void rehashPropertyMapHashTable(); 132 void rehashPropertyMapHashTable(unsigned newTableSize); 133 void createPropertyMapHashTable(); 134 void insertIntoPropertyMapHashTable(const PropertyMapEntry&); 135 void checkConsistency(); 136 137 PropertyMapHashTable* copyPropertyTable(); 138 139 void clearEnumerationCache(); 140 141 static const unsigned emptyEntryIndex = 0; 142 122 143 static const size_t s_maxTransitionLength = 64; 123 144 … … 138 159 RefPtr<PropertyNameArrayData> m_cachedPropertyNameArrayData; 139 160 140 PropertyMap m_propertyMap; 161 PropertyMapHashTable* m_propertyTable; 162 Vector<unsigned> m_deletedOffsets; 163 141 164 size_t m_propertyStorageCapacity; 142 165 … … 149 172 }; 150 173 174 inline size_t StructureID::get(const Identifier& propertyName) const 175 { 176 ASSERT(!propertyName.isNull()); 177 178 if (!m_propertyTable) 179 return WTF::notFound; 180 181 UString::Rep* rep = propertyName._ustring.rep(); 182 183 unsigned i = rep->computedHash(); 184 185 #if DUMP_PROPERTYMAP_STATS 186 ++numProbes; 187 #endif 188 189 unsigned entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask]; 190 if (entryIndex == emptyEntryIndex) 191 return WTF::notFound; 192 193 if (rep == m_propertyTable->entries()[entryIndex - 1].key) 194 return m_propertyTable->entries()[entryIndex - 1].offset; 195 196 #if DUMP_PROPERTYMAP_STATS 197 ++numCollisions; 198 #endif 199 200 unsigned k = 1 | WTF::doubleHash(rep->computedHash()); 201 202 while (1) { 203 i += k; 204 205 #if DUMP_PROPERTYMAP_STATS 206 ++numRehashes; 207 #endif 208 209 entryIndex = m_propertyTable->entryIndices[i & m_propertyTable->sizeMask]; 210 if (entryIndex == emptyEntryIndex) 211 return WTF::notFound; 212 213 if (rep == m_propertyTable->entries()[entryIndex - 1].key) 214 return m_propertyTable->entries()[entryIndex - 1].offset; 215 } 216 } 217 151 218 class StructureIDChain : public RefCounted<StructureIDChain> { 152 219 public:
Note:
See TracChangeset
for help on using the changeset viewer.