X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/2d39b0e377c0896910ee49ae70082ba665faf986..HEAD:/runtime/PropertyMapHashTable.h diff --git a/runtime/PropertyMapHashTable.h b/runtime/PropertyMapHashTable.h index 5da5cf3..b068b99 100644 --- a/runtime/PropertyMapHashTable.h +++ b/runtime/PropertyMapHashTable.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2014 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,15 +28,14 @@ #include #include #include -#include #include -#include +#include #define DUMP_PROPERTYMAP_STATS 0 #define DUMP_PROPERTYMAP_COLLISIONS 0 -#define PROPERTY_MAP_DELETED_ENTRY_KEY ((StringImpl*)1) +#define PROPERTY_MAP_DELETED_ENTRY_KEY ((UniquedStringImpl*)1) namespace JSC { @@ -78,22 +77,7 @@ inline unsigned nextPowerOf2(unsigned v) return v; } -struct PropertyMapEntry { - StringImpl* key; - PropertyOffset offset; - unsigned attributes; - WriteBarrier specificValue; - - PropertyMapEntry(VM& vm, JSCell* owner, StringImpl* key, PropertyOffset offset, unsigned attributes, JSCell* specificValue) - : key(key) - , offset(offset) - , attributes(attributes) - , specificValue(vm, owner, specificValue, WriteBarrier::MayBeNull) - { - } -}; - -class PropertyTable : public JSCell { +class PropertyTable final : public JSCell { // This is the implementation for 'iterator' and 'const_iterator', // used for iterating over the table in insertion order. @@ -136,20 +120,20 @@ class PropertyTable : public JSCell { }; public: + typedef JSCell Base; + static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal; + static const bool needsDestruction = true; - static const bool hasImmortalStructure = true; static void destroy(JSCell*); DECLARE_EXPORT_INFO; static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) { - return Structure::create(vm, globalObject, prototype, TypeInfo(CompoundType, StructureFlags), info()); + return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info()); } - static void visitChildren(JSCell*, SlotVisitor&); - - typedef StringImpl* KeyType; + typedef UniquedStringImpl* KeyType; typedef PropertyMapEntry ValueType; // The in order iterator provides overloaded * and -> to access the Value at the current position. @@ -175,7 +159,6 @@ public: // Find a value in the table. find_iterator find(const KeyType&); - find_iterator findWithString(const KeyType&); ValueType* get(const KeyType&); // Add a value to the table enum EffectOnPropertyOffset { PropertyOffsetMayChange, PropertyOffsetMustNotChange }; @@ -209,9 +192,6 @@ public: void checkConsistency(); #endif -protected: - static const unsigned StructureFlags = OverridesVisitChildren | StructureIsImmortal; - private: PropertyTable(VM&, unsigned initialCapacity); PropertyTable(VM&, const PropertyTable&); @@ -261,7 +241,7 @@ private: unsigned* m_index; unsigned m_keyCount; unsigned m_deletedCount; - OwnPtr< Vector> m_deletedOffsets; + std::unique_ptr> m_deletedOffsets; static const unsigned MinimumTableSize = 16; static const unsigned EmptyEntryIndex = 0; @@ -290,8 +270,8 @@ inline PropertyTable::const_iterator PropertyTable::end() const inline PropertyTable::find_iterator PropertyTable::find(const KeyType& key) { ASSERT(key); - ASSERT(key->isAtomic() || key->isEmptyUnique()); - unsigned hash = key->existingHash(); + ASSERT(key->isAtomic() || key->isSymbol()); + unsigned hash = IdentifierRepHash::hash(key); unsigned step = 0; #if DUMP_PROPERTYMAP_STATS @@ -306,7 +286,7 @@ inline PropertyTable::find_iterator PropertyTable::find(const KeyType& key) return std::make_pair(&table()[entryIndex - 1], hash & m_indexMask); if (!step) - step = WTF::doubleHash(key->existingHash()) | 1; + step = WTF::doubleHash(IdentifierRepHash::hash(key)) | 1; #if DUMP_PROPERTYMAP_STATS ++propertyMapHashTableStats->numCollisions; @@ -314,7 +294,7 @@ inline PropertyTable::find_iterator PropertyTable::find(const KeyType& key) #if DUMP_PROPERTYMAP_COLLISIONS dataLog("PropertyTable collision for ", key, " (", hash, ") with step ", step, "\n"); - dataLog("Collided with ", table()[entryIndex - 1].key, "(", table()[entryIndex - 1].key->existingHash(), ")\n"); + dataLog("Collided with ", table()[entryIndex - 1].key, "(", IdentifierRepHash::hash(table()[entryIndex - 1].key), ")\n"); #endif hash += step; @@ -324,12 +304,12 @@ inline PropertyTable::find_iterator PropertyTable::find(const KeyType& key) inline PropertyTable::ValueType* PropertyTable::get(const KeyType& key) { ASSERT(key); - ASSERT(key->isAtomic() || key->isEmptyUnique()); + ASSERT(key->isAtomic() || key->isSymbol()); if (!m_keyCount) return nullptr; - unsigned hash = key->existingHash(); + unsigned hash = IdentifierRepHash::hash(key); unsigned step = 0; #if DUMP_PROPERTYMAP_STATS @@ -348,36 +328,7 @@ inline PropertyTable::ValueType* PropertyTable::get(const KeyType& key) #endif if (!step) - step = WTF::doubleHash(key->existingHash()) | 1; - hash += step; - } -} - -inline PropertyTable::find_iterator PropertyTable::findWithString(const KeyType& key) -{ - ASSERT(key); - ASSERT(!key->isAtomic() && !key->hasHash()); - unsigned hash = key->hash(); - unsigned step = 0; - -#if DUMP_PROPERTYMAP_STATS - ++propertyMapHashTableStats->numLookups; -#endif - - while (true) { - unsigned entryIndex = m_index[hash & m_indexMask]; - if (entryIndex == EmptyEntryIndex) - return std::make_pair((ValueType*)0, hash & m_indexMask); - const KeyType& keyInMap = table()[entryIndex - 1].key; - if (equal(key, keyInMap) && keyInMap->isAtomic()) - return std::make_pair(&table()[entryIndex - 1], hash & m_indexMask); - -#if DUMP_PROPERTYMAP_STATS - ++propertyMapHashTableStats->numLookupProbing; -#endif - - if (!step) - step = WTF::doubleHash(key->existingHash()) | 1; + step = WTF::doubleHash(IdentifierRepHash::hash(key)) | 1; hash += step; } } @@ -468,7 +419,7 @@ inline unsigned PropertyTable::propertyStorageSize() const inline void PropertyTable::clearDeletedOffsets() { - m_deletedOffsets.clear(); + m_deletedOffsets = nullptr; } inline bool PropertyTable::hasDeletedOffset() @@ -486,7 +437,7 @@ inline PropertyOffset PropertyTable::getDeletedOffset() inline void PropertyTable::addDeletedOffset(PropertyOffset offset) { if (!m_deletedOffsets) - m_deletedOffsets = adoptPtr(new Vector); + m_deletedOffsets = std::make_unique>(); m_deletedOffsets->append(offset); }