Changeset 32650 in webkit for trunk/JavaScriptCore/wtf/RefPtrHashMap.h
- Timestamp:
- Apr 28, 2008, 10:18:15 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/RefPtrHashMap.h
r32609 r32650 25 25 // to allow for lookup by pointer instead of RefPtr, avoiding ref-count churn. 26 26 27 // FIXME: Is there a better way to do this that doesn't just copy HashMap?27 // FIXME: Find a better way that doesn't require an entire copy of the HashMap template. 28 28 29 template<typename RawKeyType, typename ValueType, typename ValueTraits, typename ValueStorageTraits, typenameHashFunctions>29 template<typename RawKeyType, typename ValueType, typename ValueTraits, typename HashFunctions> 30 30 struct RefPtrHashMapRawKeyTranslator { 31 31 typedef typename ValueType::first_type KeyType; 32 32 typedef typename ValueType::second_type MappedType; 33 typedef typename ValueStorageTraits::TraitType ValueStorageType;34 typedef typename ValueStorageTraits::FirstTraits KeyStorageTraits;35 typedef typename KeyStorageTraits::TraitType KeyStorageType;36 typedef typename ValueStorageTraits::SecondTraits MappedStorageTraits;37 typedef typename MappedStorageTraits::TraitType MappedStorageType;38 33 typedef typename ValueTraits::FirstTraits KeyTraits; 39 34 typedef typename ValueTraits::SecondTraits MappedTraits; 40 35 41 36 static unsigned hash(RawKeyType key) { return HashFunctions::hash(key); } 42 static bool equal(const Key StorageType& a, RawKeyType b) { return HashFunctions::equal(*(KeyType*)&a, b); }43 static void translate(Value StorageType& location, RawKeyType key, const MappedType& mapped)37 static bool equal(const KeyType& a, RawKeyType b) { return HashFunctions::equal(a, b); } 38 static void translate(ValueType& location, RawKeyType key, const MappedType& mapped) 44 39 { 45 40 location.first = key; … … 53 48 typedef KeyTraitsArg KeyTraits; 54 49 typedef MappedTraitsArg MappedTraits; 55 typedef Pair BaseHashTraits<KeyTraits, MappedTraits> ValueTraits;50 typedef PairHashTraits<KeyTraits, MappedTraits> ValueTraits; 56 51 57 52 public: … … 64 59 typedef HashArg HashFunctions; 65 60 66 typedef typename HashKeyStorageTraits<HashFunctions, KeyTraits>::Hash StorageHashFunctions; 67 68 typedef typename HashKeyStorageTraits<HashFunctions, KeyTraits>::Traits KeyStorageTraits; 69 typedef typename MappedTraits::StorageTraits MappedStorageTraits; 70 typedef PairHashTraits<KeyStorageTraits, MappedStorageTraits> ValueStorageTraits; 71 72 typedef typename KeyStorageTraits::TraitType KeyStorageType; 73 typedef typename MappedStorageTraits::TraitType MappedStorageType; 74 typedef typename ValueStorageTraits::TraitType ValueStorageType; 75 76 typedef HashTable<KeyStorageType, ValueStorageType, PairFirstExtractor<ValueStorageType>, 77 StorageHashFunctions, ValueStorageTraits, KeyStorageTraits> HashTableType; 78 79 typedef RefPtrHashMapRawKeyTranslator<RawKeyType, ValueType, ValueTraits, ValueStorageTraits, HashFunctions> 61 typedef HashTable<KeyType, ValueType, PairFirstExtractor<ValueType>, 62 HashFunctions, ValueTraits, KeyTraits> HashTableType; 63 64 typedef RefPtrHashMapRawKeyTranslator<RawKeyType, ValueType, ValueTraits, HashFunctions> 80 65 RawKeyTranslator; 81 66 … … 83 68 typedef HashTableIteratorAdapter<HashTableType, ValueType> iterator; 84 69 typedef HashTableConstIteratorAdapter<HashTableType, ValueType> const_iterator; 85 86 HashMap();87 HashMap(const HashMap&);88 HashMap& operator=(const HashMap&);89 ~HashMap();90 70 91 71 void swap(HashMap&); … … 134 114 pair<iterator, bool> inlineAdd(const KeyType&, const MappedType&); 135 115 pair<iterator, bool> inlineAdd(RawKeyType, const MappedType&); 136 void refAll();137 void derefAll();138 116 139 117 HashTableType m_impl; … … 141 119 142 120 template<typename T, typename U, typename V, typename W, typename X> 143 inline void HashMap<RefPtr<T>, U, V, W, X>::refAll()144 {145 HashTableRefCounter<HashTableType, ValueTraits>::refAll(m_impl);146 }147 148 template<typename T, typename U, typename V, typename W, typename X>149 inline void HashMap<RefPtr<T>, U, V, W, X>::derefAll()150 {151 HashTableRefCounter<HashTableType, ValueTraits>::derefAll(m_impl);152 }153 154 template<typename T, typename U, typename V, typename W, typename X>155 inline HashMap<RefPtr<T>, U, V, W, X>::HashMap()156 {157 }158 159 template<typename T, typename U, typename V, typename W, typename X>160 inline HashMap<RefPtr<T>, U, V, W, X>::HashMap(const HashMap& other)161 : m_impl(other.m_impl)162 {163 refAll();164 }165 166 template<typename T, typename U, typename V, typename W, typename X>167 inline HashMap<RefPtr<T>, U, V, W, X>& HashMap<RefPtr<T>, U, V, W, X>::operator=(const HashMap& other)168 {169 HashMap tmp(other);170 swap(tmp);171 return *this;172 }173 174 template<typename T, typename U, typename V, typename W, typename X>175 121 inline void HashMap<RefPtr<T>, U, V, W, X>::swap(HashMap& other) 176 122 { 177 123 m_impl.swap(other.m_impl); 178 }179 180 template<typename T, typename U, typename V, typename W, typename X>181 inline HashMap<RefPtr<T>, U, V, W, X>::~HashMap()182 {183 derefAll();184 124 } 185 125 … … 229 169 inline typename HashMap<RefPtr<T>, U, V, W, X>::iterator HashMap<RefPtr<T>, U, V, W, X>::find(const KeyType& key) 230 170 { 231 return m_impl.find( *(const KeyStorageType*)&key);171 return m_impl.find(key); 232 172 } 233 173 … … 241 181 inline typename HashMap<RefPtr<T>, U, V, W, X>::const_iterator HashMap<RefPtr<T>, U, V, W, X>::find(const KeyType& key) const 242 182 { 243 return m_impl.find( *(const KeyStorageType*)&key);183 return m_impl.find(key); 244 184 } 245 185 … … 253 193 inline bool HashMap<RefPtr<T>, U, V, W, X>::contains(const KeyType& key) const 254 194 { 255 return m_impl.contains( *(const KeyStorageType*)&key);195 return m_impl.contains(key); 256 196 } 257 197 … … 266 206 HashMap<RefPtr<T>, U, V, W, X>::inlineAdd(const KeyType& key, const MappedType& mapped) 267 207 { 268 const bool canReplaceDeletedKey = !KeyTraits::needsDestruction || KeyStorageTraits::needsDestruction; 269 typedef HashMapTranslator<canReplaceDeletedKey, ValueType, ValueTraits, ValueStorageTraits, HashFunctions> TranslatorType; 208 typedef HashMapTranslator<ValueType, ValueTraits, HashFunctions> TranslatorType; 270 209 return m_impl.template add<KeyType, MappedType, TranslatorType>(key, mapped); 271 210 } … … 320 259 HashMap<RefPtr<T>, U, V, W, MappedTraits>::get(const KeyType& key) const 321 260 { 322 Value StorageType* entry = const_cast<HashTableType&>(m_impl).lookup(*(const KeyStorageType*)&key);261 ValueType* entry = const_cast<HashTableType&>(m_impl).lookup(key); 323 262 if (!entry) 324 263 return MappedTraits::emptyValue(); 325 return ((ValueType *)entry)->second;264 return entry->second; 326 265 } 327 266 … … 349 288 return; 350 289 m_impl.checkTableConsistency(); 351 RefCounter<ValueTraits, ValueStorageTraits>::deref(*it.m_impl);352 290 m_impl.removeWithoutEntryConsistencyCheck(it.m_impl); 353 291 } … … 368 306 inline void HashMap<RefPtr<T>, U, V, W, X>::clear() 369 307 { 370 derefAll();371 308 m_impl.clear(); 372 309 }
Note:
See TracChangeset
for help on using the changeset viewer.