| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv
ed. |
| 3 * Copyright (C) 2008 David Levin <levin@chromium.org> | 3 * Copyright (C) 2008 David Levin <levin@chromium.org> |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 #endif | 90 #endif |
| 91 | 91 |
| 92 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | 92 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> |
| 93 class HashTable; | 93 class HashTable; |
| 94 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | 94 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> |
| 95 class HashTableIterator; | 95 class HashTableIterator; |
| 96 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | 96 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> |
| 97 class HashTableConstIterator; | 97 class HashTableConstIterator; |
| 98 template<typename Value, typename HashFunctions, typename HashTraits, typena
me Allocator> | 98 template<typename Value, typename HashFunctions, typename HashTraits, typena
me Allocator> |
| 99 class LinkedHashSet; | 99 class LinkedHashSet; |
| 100 template<bool x, typename T, typename U, typename V, typename W, typename X,
typename Y, typename Z> | 100 template<WeakHandlingFlag x, typename T, typename U, typename V, typename W,
typename X, typename Y, typename Z> |
| 101 struct WeakProcessingHashTableHelper; | 101 struct WeakProcessingHashTableHelper; |
| 102 | 102 |
| 103 typedef enum { HashItemKnownGood } HashItemKnownGoodTag; | 103 typedef enum { HashItemKnownGood } HashItemKnownGoodTag; |
| 104 | 104 |
| 105 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | 105 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> |
| 106 class HashTableConstIterator { | 106 class HashTableConstIterator { |
| 107 private: | 107 private: |
| 108 typedef HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTrait
s, Allocator> HashTableType; | 108 typedef HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTrait
s, Allocator> HashTableType; |
| 109 typedef HashTableIterator<Key, Value, Extractor, HashFunctions, Traits,
KeyTraits, Allocator> iterator; | 109 typedef HashTableIterator<Key, Value, Extractor, HashFunctions, Traits,
KeyTraits, Allocator> iterator; |
| 110 typedef HashTableConstIterator<Key, Value, Extractor, HashFunctions, Tra
its, KeyTraits, Allocator> const_iterator; | 110 typedef HashTableConstIterator<Key, Value, Extractor, HashFunctions, Tra
its, KeyTraits, Allocator> const_iterator; |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 unsigned m_deletedCount; | 525 unsigned m_deletedCount; |
| 526 #ifdef ASSERT_ENABLED | 526 #ifdef ASSERT_ENABLED |
| 527 unsigned m_modifications; | 527 unsigned m_modifications; |
| 528 #endif | 528 #endif |
| 529 | 529 |
| 530 #if DUMP_HASHTABLE_STATS_PER_TABLE | 530 #if DUMP_HASHTABLE_STATS_PER_TABLE |
| 531 public: | 531 public: |
| 532 mutable OwnPtr<Stats> m_stats; | 532 mutable OwnPtr<Stats> m_stats; |
| 533 #endif | 533 #endif |
| 534 | 534 |
| 535 template<bool x, typename T, typename U, typename V, typename W, typenam
e X, typename Y, typename Z> friend struct WeakProcessingHashTableHelper; | 535 template<WeakHandlingFlag x, typename T, typename U, typename V, typenam
e W, typename X, typename Y, typename Z> friend struct WeakProcessingHashTableHe
lper; |
| 536 template<typename T, typename U, typename V, typename W> friend class Li
nkedHashSet; | 536 template<typename T, typename U, typename V, typename W> friend class Li
nkedHashSet; |
| 537 }; | 537 }; |
| 538 | 538 |
| 539 // Set all the bits to one after the most significant bit: 00110101010 -> 00
111111111. | 539 // Set all the bits to one after the most significant bit: 00110101010 -> 00
111111111. |
| 540 template<unsigned size> struct OneifyLowBits; | 540 template<unsigned size> struct OneifyLowBits; |
| 541 template<> | 541 template<> |
| 542 struct OneifyLowBits<0> { | 542 struct OneifyLowBits<0> { |
| 543 static const unsigned value = 0; | 543 static const unsigned value = 0; |
| 544 }; | 544 }; |
| 545 template<unsigned number> | 545 template<unsigned number> |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 } | 1090 } |
| 1091 | 1091 |
| 1092 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | 1092 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> |
| 1093 HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator
>& HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>
::operator=(const HashTable& other) | 1093 HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator
>& HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>
::operator=(const HashTable& other) |
| 1094 { | 1094 { |
| 1095 HashTable tmp(other); | 1095 HashTable tmp(other); |
| 1096 swap(tmp); | 1096 swap(tmp); |
| 1097 return *this; | 1097 return *this; |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 template<bool isWeak, typename Key, typename Value, typename Extractor, type
name HashFunctions, typename Traits, typename KeyTraits, typename Allocator> | 1100 template<WeakHandlingFlag weakHandlingFlag, typename Key, typename Value, ty
pename Extractor, typename HashFunctions, typename Traits, typename KeyTraits, t
ypename Allocator> |
| 1101 struct WeakProcessingHashTableHelper; | 1101 struct WeakProcessingHashTableHelper; |
| 1102 | 1102 |
| 1103 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | 1103 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> |
| 1104 struct WeakProcessingHashTableHelper<false, Key, Value, Extractor, HashFunct
ions, Traits, KeyTraits, Allocator> { | 1104 struct WeakProcessingHashTableHelper<NoWeakHandlingInCollections, Key, Value
, Extractor, HashFunctions, Traits, KeyTraits, Allocator> { |
| 1105 static void process(typename Allocator::Visitor* visitor, void* closure)
{ } | 1105 static void process(typename Allocator::Visitor* visitor, void* closure)
{ } |
| 1106 }; | 1106 }; |
| 1107 | 1107 |
| 1108 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | 1108 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> |
| 1109 struct WeakProcessingHashTableHelper<true, Key, Value, Extractor, HashFuncti
ons, Traits, KeyTraits, Allocator> { | 1109 struct WeakProcessingHashTableHelper<WeakHandlingInCollections, Key, Value,
Extractor, HashFunctions, Traits, KeyTraits, Allocator> { |
| 1110 static void process(typename Allocator::Visitor* visitor, void* closure) | 1110 static void process(typename Allocator::Visitor* visitor, void* closure) |
| 1111 { | 1111 { |
| 1112 typedef HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyT
raits, Allocator> HashTableType; | 1112 typedef HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyT
raits, Allocator> HashTableType; |
| 1113 HashTableType* table = reinterpret_cast<HashTableType*>(closure); | 1113 HashTableType* table = reinterpret_cast<HashTableType*>(closure); |
| 1114 if (table->m_table) { | 1114 if (table->m_table) { |
| 1115 // This just marks it live and does not push anything onto the | 1115 // This just marks it live and does not push anything onto the |
| 1116 // marking stack. | 1116 // marking stack. |
| 1117 Allocator::markNoTracing(visitor, table->m_table); | 1117 Allocator::markNoTracing(visitor, table->m_table); |
| 1118 // Now perform weak processing (this is a no-op if the backing | 1118 // Now perform weak processing (this is a no-op if the backing |
| 1119 // was accessible through an iterator and was already marked | 1119 // was accessible through an iterator and was already marked |
| 1120 // strongly). | 1120 // strongly). |
| 1121 for (typename HashTableType::ValueType* element = table->m_table
+ table->m_tableSize - 1; element >= table->m_table; element--) { | 1121 for (typename HashTableType::ValueType* element = table->m_table
+ table->m_tableSize - 1; element >= table->m_table; element--) { |
| 1122 if (!HashTableType::isEmptyOrDeletedBucket(*element)) { | 1122 if (!HashTableType::isEmptyOrDeletedBucket(*element)) { |
| 1123 if (Allocator::hasDeadMember(visitor, *element)) { | 1123 if (Traits::shouldRemoveFromCollection(visitor, *element
)) { |
| 1124 table->registerModification(); | 1124 table->registerModification(); |
| 1125 HashTableType::deleteBucket(*element); // Also calls
the destructor. | 1125 HashTableType::deleteBucket(*element); // Also calls
the destructor. |
| 1126 table->m_deletedCount++; | 1126 table->m_deletedCount++; |
| 1127 table->m_keyCount--; | 1127 table->m_keyCount--; |
| 1128 // We don't rehash the backing until the next add | 1128 // We don't rehash the backing until the next add |
| 1129 // or delete, because that would cause allocation | 1129 // or delete, because that would cause allocation |
| 1130 // during GC. | 1130 // during GC. |
| 1131 } | 1131 } |
| 1132 } | 1132 } |
| 1133 } | 1133 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1149 // Instead we will mark the pointers below. However, for backing | 1149 // Instead we will mark the pointers below. However, for backing |
| 1150 // stores that contain weak pointers the handling is rather different. | 1150 // stores that contain weak pointers the handling is rather different. |
| 1151 // We don't mark the backing store here, so the marking GC will leave | 1151 // We don't mark the backing store here, so the marking GC will leave |
| 1152 // the backing unmarked. If the backing is found in any other way than | 1152 // the backing unmarked. If the backing is found in any other way than |
| 1153 // through its HashTable (ie from an iterator) then the mark bit will | 1153 // through its HashTable (ie from an iterator) then the mark bit will |
| 1154 // be set and the pointers will be marked strongly, avoiding problems | 1154 // be set and the pointers will be marked strongly, avoiding problems |
| 1155 // with iterating over things that disappear due to weak processing | 1155 // with iterating over things that disappear due to weak processing |
| 1156 // while we are iterating over them. The weakProcessing callback will | 1156 // while we are iterating over them. The weakProcessing callback will |
| 1157 // mark the backing as a void pointer, and will perform weak processing | 1157 // mark the backing as a void pointer, and will perform weak processing |
| 1158 // if needed. | 1158 // if needed. |
| 1159 if (!Traits::isWeak) | 1159 if (Traits::weakHandlingFlag == NoWeakHandlingInCollections) |
| 1160 Allocator::markNoTracing(visitor, m_table); | 1160 Allocator::markNoTracing(visitor, m_table); |
| 1161 else | 1161 else |
| 1162 Allocator::registerWeakMembers(visitor, this, m_table, WeakProcessin
gHashTableHelper<Traits::isWeak, Key, Value, Extractor, HashFunctions, Traits, K
eyTraits, Allocator>::process); | 1162 Allocator::registerWeakMembers(visitor, this, m_table, WeakProcessin
gHashTableHelper<Traits::weakHandlingFlag, Key, Value, Extractor, HashFunctions,
Traits, KeyTraits, Allocator>::process); |
| 1163 if (ShouldBeTraced<Traits>::value) { | 1163 if (ShouldBeTraced<Traits>::value) { |
| 1164 for (ValueType* element = m_table + m_tableSize - 1; element >= m_ta
ble; element--) { | 1164 for (ValueType* element = m_table + m_tableSize - 1; element >= m_ta
ble; element--) { |
| 1165 if (!isEmptyOrDeletedBucket(*element)) | 1165 if (!isEmptyOrDeletedBucket(*element)) |
| 1166 Allocator::template trace<ValueType, Traits>(visitor, *eleme
nt); | 1166 Allocator::template trace<ValueType, Traits>(visitor, *eleme
nt); |
| 1167 } | 1167 } |
| 1168 } | 1168 } |
| 1169 } | 1169 } |
| 1170 | 1170 |
| 1171 // iterator adapters | 1171 // iterator adapters |
| 1172 | 1172 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 CollectionIterator end(toBeRemoved.end()); | 1267 CollectionIterator end(toBeRemoved.end()); |
| 1268 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) | 1268 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) |
| 1269 collection.remove(*it); | 1269 collection.remove(*it); |
| 1270 } | 1270 } |
| 1271 | 1271 |
| 1272 } // namespace WTF | 1272 } // namespace WTF |
| 1273 | 1273 |
| 1274 #include "wtf/HashIterators.h" | 1274 #include "wtf/HashIterators.h" |
| 1275 | 1275 |
| 1276 #endif // WTF_HashTable_h | 1276 #endif // WTF_HashTable_h |
| OLD | NEW |