Changeset 36701 in webkit for trunk/JavaScriptCore/kjs/StructureID.cpp
- Timestamp:
- Sep 19, 2008, 9:35:33 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/StructureID.cpp
r36696 r36701 30 30 #include "JSObject.h" 31 31 #include "PropertyNameArray.h" 32 #include "lookup.h" 32 33 #include <wtf/RefPtr.h> 33 34 … … 49 50 } 50 51 51 void StructureID::getEnumerablePropertyNames(PropertyNameArray& propertyNames) const 52 { 53 if (m_cachedPropertyNameArray.isEmpty()) 54 m_propertyMap.getEnumerablePropertyNames(m_cachedPropertyNameArray); 55 56 if (!propertyNames.size()) { 57 for (size_t i = 0; i < m_cachedPropertyNameArray.size(); ++i) 58 propertyNames.addKnownUnique(m_cachedPropertyNameArray[i]); 59 } else { 60 for (size_t i = 0; i < m_cachedPropertyNameArray.size(); ++i) 61 propertyNames.add(m_cachedPropertyNameArray[i]); 62 } 52 static bool structureIDChainsAreEqual(StructureIDChain* chainA, StructureIDChain* chainB) 53 { 54 if (!chainA || !chainB) 55 return false; 56 57 RefPtr<StructureID>* a = chainA->head(); 58 RefPtr<StructureID>* b = chainB->head(); 59 while (1) { 60 if (*a != *b) 61 return false; 62 if (!*a) 63 return true; 64 a++; 65 b++; 66 } 67 } 68 69 void StructureID::getEnumerablePropertyNames(ExecState* exec, PropertyNameArray& propertyNames, JSObject* baseObject) 70 { 71 bool shouldCache = !(propertyNames.size() || m_isDictionary); 72 73 if (shouldCache && m_cachedPropertyNameArrayData) { 74 if (structureIDChainsAreEqual(m_cachedPropertyNameArrayData->cachedPrototypeChain(), cachedPrototypeChain())) { 75 propertyNames.setData(m_cachedPropertyNameArrayData); 76 return; 77 } 78 } 79 80 m_propertyMap.getEnumerablePropertyNames(propertyNames); 81 82 // Add properties from the static hashtables of properties 83 for (const ClassInfo* info = baseObject->classInfo(); info; info = info->parentClass) { 84 const HashTable* table = info->propHashTable(exec); 85 if (!table) 86 continue; 87 table->initializeIfNeeded(exec); 88 ASSERT(table->table); 89 int hashSizeMask = table->hashSizeMask; 90 const HashEntry* entry = table->table; 91 for (int i = 0; i <= hashSizeMask; ++i, ++entry) { 92 if (entry->key && !(entry->attributes & DontEnum)) 93 propertyNames.add(entry->key); 94 } 95 } 96 97 if (m_prototype->isObject()) 98 static_cast<JSObject*>(m_prototype)->getPropertyNames(exec, propertyNames); 99 100 if (shouldCache) { 101 m_cachedPropertyNameArrayData = propertyNames.data(); 102 103 StructureIDChain* chain = cachedPrototypeChain(); 104 if (!chain) 105 chain = createCachedPrototypeChain(); 106 m_cachedPropertyNameArrayData->setCachedPrototypeChain(chain); 107 } 108 } 109 110 void StructureID::clearEnumerationCache() 111 { 112 m_cachedPropertyNameArrayData.clear(); 63 113 } 64 114 … … 151 201 } 152 202 203 StructureIDChain* StructureID::createCachedPrototypeChain() 204 { 205 ASSERT(m_type == ObjectType); 206 ASSERT(!m_cachedPrototypeChain); 207 208 JSValue* prototype = storedPrototype(); 209 if (JSImmediate::isImmediate(prototype)) 210 return 0; 211 212 RefPtr<StructureIDChain> chain = StructureIDChain::create(static_cast<JSObject*>(prototype)->structureID()); 213 setCachedPrototypeChain(chain.release()); 214 return cachedPrototypeChain(); 215 } 216 153 217 StructureIDChain::StructureIDChain(StructureID* structureID) 154 218 {
Note:
See TracChangeset
for help on using the changeset viewer.