summaryrefslogtreecommitdiff
path: root/chromium/third_party/WebKit/Source/wtf/HashTable.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/wtf/HashTable.h')
-rw-r--r--chromium/third_party/WebKit/Source/wtf/HashTable.h55
1 files changed, 50 insertions, 5 deletions
diff --git a/chromium/third_party/WebKit/Source/wtf/HashTable.h b/chromium/third_party/WebKit/Source/wtf/HashTable.h
index c85ddc2ad79..f8741730afd 100644
--- a/chromium/third_party/WebKit/Source/wtf/HashTable.h
+++ b/chromium/third_party/WebKit/Source/wtf/HashTable.h
@@ -151,6 +151,7 @@ private:
// ListHashSet, which has its own iterators that tolerate modification
// of the underlying set.
ASSERT(m_containerModifications == m_container->modifications());
+ ASSERT(!m_container->accessForbidden());
}
public:
@@ -411,7 +412,10 @@ public:
ASSERT(!Allocator::isGarbageCollected);
if (LIKELY(!m_table))
return;
+ RELEASE_ASSERT(!m_accessForbidden);
+ m_accessForbidden = true;
deleteAllBucketsAndDeallocate(m_table, m_tableSize);
+ m_accessForbidden = false;
m_table = nullptr;
}
@@ -428,9 +432,21 @@ public:
const_iterator begin() const { return isEmpty() ? end() : makeConstIterator(m_table); }
const_iterator end() const { return makeKnownGoodConstIterator(m_table + m_tableSize); }
- unsigned size() const { return m_keyCount; }
- unsigned capacity() const { return m_tableSize; }
- bool isEmpty() const { return !m_keyCount; }
+ unsigned size() const
+ {
+ RELEASE_ASSERT(!m_accessForbidden);
+ return m_keyCount;
+ }
+ unsigned capacity() const
+ {
+ RELEASE_ASSERT(!m_accessForbidden);
+ return m_tableSize;
+ }
+ bool isEmpty() const
+ {
+ RELEASE_ASSERT(!m_accessForbidden);
+ return !m_keyCount;
+ }
void reserveCapacityForSize(unsigned size);
@@ -468,6 +484,7 @@ public:
template <typename VisitorDispatcher> void trace(VisitorDispatcher);
+ bool accessForbidden() const { return m_accessForbidden; }
#if ENABLE(ASSERT)
int64_t modifications() const { return m_modifications; }
void registerModification() { m_modifications++; }
@@ -513,7 +530,11 @@ private:
ValueType* reinsert(ValueType&);
static void initializeBucket(ValueType& bucket);
- static void deleteBucket(ValueType& bucket) { bucket.~ValueType(); Traits::constructDeletedValue(bucket, Allocator::isGarbageCollected); }
+ static void deleteBucket(ValueType& bucket)
+ {
+ bucket.~ValueType();
+ Traits::constructDeletedValue(bucket, Allocator::isGarbageCollected);
+ }
FullLookupType makeLookupResult(ValueType* position, bool found, unsigned hash)
{ return FullLookupType(LookupType(position, found), hash); }
@@ -540,8 +561,9 @@ private:
ValueType* m_table;
unsigned m_tableSize;
unsigned m_keyCount;
- unsigned m_deletedCount:31;
+ unsigned m_deletedCount:30;
unsigned m_queueFlag:1;
+ unsigned m_accessForbidden:1;
#if ENABLE(ASSERT)
unsigned m_modifications;
#endif
@@ -602,6 +624,7 @@ inline HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Alloca
, m_keyCount(0)
, m_deletedCount(0)
, m_queueFlag(false)
+ , m_accessForbidden(false)
#if ENABLE(ASSERT)
, m_modifications(0)
#endif
@@ -652,6 +675,7 @@ template <typename Key, typename Value, typename Extractor, typename HashFunctio
template <typename HashTranslator, typename T>
inline const Value* HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::lookup(T key) const
{
+ RELEASE_ASSERT(!m_accessForbidden);
ASSERT((HashTableKeyChecker<HashTranslator, KeyTraits, HashFunctions::safeToCompareToEmptyOrDeleted>::checkKey(key)));
const ValueType* table = m_table;
if (!table)
@@ -691,6 +715,7 @@ template <typename Key, typename Value, typename Extractor, typename HashFunctio
template <typename HashTranslator, typename T>
inline typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::LookupType HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::lookupForWriting(const T& key)
{
+ RELEASE_ASSERT(!m_accessForbidden);
ASSERT(m_table);
registerModification();
@@ -733,6 +758,7 @@ template <typename Key, typename Value, typename Extractor, typename HashFunctio
template <typename HashTranslator, typename T>
inline typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::FullLookupType HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::fullLookupForWriting(const T& key)
{
+ RELEASE_ASSERT(!m_accessForbidden);
ASSERT(m_table);
registerModification();
@@ -801,6 +827,7 @@ template <typename Key, typename Value, typename Extractor, typename HashFunctio
template <typename HashTranslator, typename T, typename Extra>
typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::AddResult HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::add(const T& key, const Extra& extra)
{
+ RELEASE_ASSERT(!m_accessForbidden);
ASSERT(Allocator::isAllocationAllowed());
if (!m_table)
expand();
@@ -866,6 +893,7 @@ template <typename Key, typename Value, typename Extractor, typename HashFunctio
template <typename HashTranslator, typename T, typename Extra>
typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::AddResult HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::addPassingHashCode(const T& key, const Extra& extra)
{
+ RELEASE_ASSERT(!m_accessForbidden);
ASSERT(Allocator::isAllocationAllowed());
if (!m_table)
expand();
@@ -947,6 +975,7 @@ bool HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocato
template <typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits, typename Allocator>
void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::remove(ValueType* pos)
{
+ RELEASE_ASSERT(!m_accessForbidden);
registerModification();
#if DUMP_HASHTABLE_STATS
atomicIncrement(&HashTableStats::numRemoves);
@@ -955,7 +984,10 @@ void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocato
++m_stats->numRemoves;
#endif
+ RELEASE_ASSERT(!m_accessForbidden);
+ m_accessForbidden = true;
deleteBucket(*pos);
+ m_accessForbidden = false;
++m_deletedCount;
--m_keyCount;
@@ -1092,7 +1124,11 @@ Value* HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Alloca
initializeBucket(originalTable[i]);
}
newEntry = rehashTo(originalTable, newTableSize, newEntry);
+
+ RELEASE_ASSERT(!m_accessForbidden);
+ m_accessForbidden = true;
deleteAllBucketsAndDeallocate(temporaryTable, oldTableSize);
+ m_accessForbidden = false;
return newEntry;
}
@@ -1162,7 +1198,11 @@ Value* HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Alloca
ValueType* newTable = allocateTable(newTableSize);
Value* newEntry = rehashTo(newTable, newTableSize, entry);
+
+ RELEASE_ASSERT(!m_accessForbidden);
+ m_accessForbidden = true;
deleteAllBucketsAndDeallocate(oldTable, oldTableSize);
+ m_accessForbidden = false;
return newEntry;
}
@@ -1174,7 +1214,10 @@ void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocato
if (!m_table)
return;
+ RELEASE_ASSERT(!m_accessForbidden);
+ m_accessForbidden = true;
deleteAllBucketsAndDeallocate(m_table, m_tableSize);
+ m_accessForbidden = false;
m_table = nullptr;
m_tableSize = 0;
m_keyCount = 0;
@@ -1187,6 +1230,7 @@ HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::H
, m_keyCount(0)
, m_deletedCount(0)
, m_queueFlag(false)
+ , m_accessForbidden(false)
#if ENABLE(ASSERT)
, m_modifications(0)
#endif
@@ -1205,6 +1249,7 @@ HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::H
template <typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits, typename Allocator>
void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::swap(HashTable& other)
{
+ RELEASE_ASSERT(!m_accessForbidden);
std::swap(m_table, other.m_table);
std::swap(m_tableSize, other.m_tableSize);
std::swap(m_keyCount, other.m_keyCount);