Ignore:
Timestamp:
Oct 8, 2009, 4:24:55 PM (16 years ago)
Author:
[email protected]
Message:

Migrated some code that didn't belong out of Structure.

Patch by Geoffrey Garen <[email protected]> on 2009-10-08
Reviewed by Sam Weinig.

SunSpider says maybe 1.03x faster.

  • runtime/JSCell.h: Nixed Structure::markAggregate, and made marking of

a Structure's prototype the direct responsility of the object using it.
(Giving Structure a mark function was misleading because it implied that
all live structures get marked during GC, when they don't.)

  • runtime/JSGlobalObject.cpp:

(JSC::markIfNeeded):
(JSC::JSGlobalObject::markChildren): Added code to mark prototypes stored
on the global object. Maybe this wasn't necessary, but now we don't have
to wonder.

  • runtime/JSObject.cpp:

(JSC::JSObject::getPropertyNames):
(JSC::JSObject::getOwnPropertyNames):
(JSC::JSObject::getEnumerableNamesFromClassInfoTable):

  • runtime/JSObject.h:

(JSC::JSObject::markChildrenDirect):

  • runtime/PropertyNameArray.h:
  • runtime/Structure.cpp:
  • runtime/Structure.h:

(JSC::Structure::setEnumerationCache):
(JSC::Structure::enumerationCache): Moved property name gathering code
from Structure to JSObject because having a Structure iterate its JSObject
was a layering violation. A JSObject is implemented using a Structure; not
the other way around.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Structure.cpp

    r49328 r49331  
    283283}
    284284
    285 void Structure::getOwnEnumerablePropertyNames(ExecState* exec, PropertyNameArray& propertyNames, JSObject* baseObject)
    286 {
    287     getEnumerableNamesFromPropertyTable(propertyNames);
    288     getEnumerableNamesFromClassInfoTable(exec, baseObject->classInfo(), propertyNames);
    289 }
    290 
    291 void Structure::getEnumerablePropertyNames(ExecState* exec, PropertyNameArray& propertyNames, JSObject* baseObject)
    292 {
    293     bool shouldCache = propertyNames.shouldCache() && !(propertyNames.size() || isDictionary());
    294 
    295     if (shouldCache && m_cachedPropertyNameArrayData) {
    296         if (m_cachedPropertyNameArrayData->cachedPrototypeChain() == prototypeChain(exec)) {
    297             propertyNames.setData(m_cachedPropertyNameArrayData);
    298             return;
    299         }
    300         clearEnumerationCache();
    301     }
    302 
    303     baseObject->getOwnPropertyNames(exec, propertyNames);
    304 
    305     if (m_prototype.isObject()) {
    306         propertyNames.setShouldCache(false); // No need for our prototypes to waste memory on caching, since they're not being enumerated directly.
    307         JSObject* prototype = asObject(m_prototype);
    308         while(1) {
    309             if (!prototype->structure()->typeInfo().hasDefaultGetPropertyNames()) {
    310                 prototype->getPropertyNames(exec, propertyNames);
    311                 break;
    312             }
    313             prototype->getOwnPropertyNames(exec, propertyNames);
    314             JSValue nextProto = prototype->prototype();
    315             if (!nextProto.isObject())
    316                 break;
    317             prototype = asObject(nextProto);
    318         }
    319     }
    320 
    321     if (shouldCache) {
    322         StructureChain* protoChain = prototypeChain(exec);
    323         m_cachedPropertyNameArrayData = propertyNames.data();
    324         if (!protoChain->isCacheable())
    325             return;
    326         m_cachedPropertyNameArrayData->setCachedPrototypeChain(protoChain);
    327         m_cachedPropertyNameArrayData->setCachedStructure(this);
    328     }
    329 }
    330 
    331285void Structure::clearEnumerationCache()
    332286{
     
    10581012}
    10591013
    1060 void Structure::getEnumerableNamesFromPropertyTable(PropertyNameArray& propertyNames)
     1014void Structure::getEnumerablePropertyNames(PropertyNameArray& propertyNames)
    10611015{
    10621016    materializePropertyMapIfNecessary();
     
    11121066        for (size_t i = 0; i < sortedEnumerables.size(); ++i)
    11131067            propertyNames.add(sortedEnumerables[i]->key);
    1114     }
    1115 }
    1116 
    1117 void Structure::getEnumerableNamesFromClassInfoTable(ExecState* exec, const ClassInfo* classInfo, PropertyNameArray& propertyNames)
    1118 {
    1119     // Add properties from the static hashtables of properties
    1120     for (; classInfo; classInfo = classInfo->parentClass) {
    1121         const HashTable* table = classInfo->propHashTable(exec);
    1122         if (!table)
    1123             continue;
    1124         table->initializeIfNeeded(exec);
    1125         ASSERT(table->table);
    1126 
    1127         int hashSizeMask = table->compactSize - 1;
    1128         const HashEntry* entry = table->table;
    1129         for (int i = 0; i <= hashSizeMask; ++i, ++entry) {
    1130             if (entry->key() && !(entry->attributes() & DontEnum))
    1131                 propertyNames.add(entry->key());
    1132         }
    11331068    }
    11341069}
Note: See TracChangeset for help on using the changeset viewer.