| 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 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // The needsDestruction flag is used to optimize destruction and rehashi
ng. | 57 // The needsDestruction flag is used to optimize destruction and rehashi
ng. |
| 58 static const bool needsDestruction = true; | 58 static const bool needsDestruction = true; |
| 59 | 59 |
| 60 // The starting table size. Can be overridden when we know beforehand th
at | 60 // The starting table size. Can be overridden when we know beforehand th
at |
| 61 // a hash table will have at least N entries. | 61 // a hash table will have at least N entries. |
| 62 #if defined(MEMORY_SANITIZER_INITIAL_SIZE) | 62 #if defined(MEMORY_SANITIZER_INITIAL_SIZE) |
| 63 static const unsigned minimumTableSize = 1; | 63 static const unsigned minimumTableSize = 1; |
| 64 #else | 64 #else |
| 65 static const unsigned minimumTableSize = 8; | 65 static const unsigned minimumTableSize = 8; |
| 66 #endif | 66 #endif |
| 67 | |
| 68 template<typename U = void> | |
| 69 struct NeedsTracingLazily { | |
| 70 static const bool value = NeedsTracing<T>::value; | |
| 71 }; | |
| 72 static const WeakHandlingFlag weakHandlingFlag = IsWeak<T>::value ? Weak
HandlingInCollections : NoWeakHandlingInCollections; | 67 static const WeakHandlingFlag weakHandlingFlag = IsWeak<T>::value ? Weak
HandlingInCollections : NoWeakHandlingInCollections; |
| 73 }; | 68 }; |
| 74 | 69 |
| 75 // Default integer traits disallow both 0 and -1 as keys (max value instead
of -1 for unsigned). | 70 // Default integer traits disallow both 0 and -1 as keys (max value instead
of -1 for unsigned). |
| 76 template<typename T> struct GenericHashTraitsBase<true, T> : GenericHashTrai
tsBase<false, T> { | 71 template<typename T> struct GenericHashTraitsBase<true, T> : GenericHashTrai
tsBase<false, T> { |
| 77 static const bool emptyValueIsZero = true; | 72 static const bool emptyValueIsZero = true; |
| 78 static const bool needsDestruction = false; | 73 static const bool needsDestruction = false; |
| 79 static void constructDeletedValue(T& slot, bool) { slot = static_cast<T>
(-1); } | 74 static void constructDeletedValue(T& slot, bool) { slot = static_cast<T>
(-1); } |
| 80 static bool isDeletedValue(T value) { return value == static_cast<T>(-1)
; } | 75 static bool isDeletedValue(T value) { return value == static_cast<T>(-1)
; } |
| 81 }; | 76 }; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 struct KeyValuePairHashTraits : GenericHashTraits<KeyValuePair<typename KeyT
raitsArg::TraitType, typename ValueTraitsArg::TraitType> > { | 273 struct KeyValuePairHashTraits : GenericHashTraits<KeyValuePair<typename KeyT
raitsArg::TraitType, typename ValueTraitsArg::TraitType> > { |
| 279 typedef KeyTraitsArg KeyTraits; | 274 typedef KeyTraitsArg KeyTraits; |
| 280 typedef ValueTraitsArg ValueTraits; | 275 typedef ValueTraitsArg ValueTraits; |
| 281 typedef KeyValuePair<typename KeyTraits::TraitType, typename ValueTraits
::TraitType> TraitType; | 276 typedef KeyValuePair<typename KeyTraits::TraitType, typename ValueTraits
::TraitType> TraitType; |
| 282 typedef KeyValuePair<typename KeyTraits::EmptyValueType, typename ValueT
raits::EmptyValueType> EmptyValueType; | 277 typedef KeyValuePair<typename KeyTraits::EmptyValueType, typename ValueT
raits::EmptyValueType> EmptyValueType; |
| 283 | 278 |
| 284 static const bool emptyValueIsZero = KeyTraits::emptyValueIsZero && Valu
eTraits::emptyValueIsZero; | 279 static const bool emptyValueIsZero = KeyTraits::emptyValueIsZero && Valu
eTraits::emptyValueIsZero; |
| 285 static EmptyValueType emptyValue() { return KeyValuePair<typename KeyTra
its::EmptyValueType, typename ValueTraits::EmptyValueType>(KeyTraits::emptyValue
(), ValueTraits::emptyValue()); } | 280 static EmptyValueType emptyValue() { return KeyValuePair<typename KeyTra
its::EmptyValueType, typename ValueTraits::EmptyValueType>(KeyTraits::emptyValue
(), ValueTraits::emptyValue()); } |
| 286 | 281 |
| 287 static const bool needsDestruction = KeyTraits::needsDestruction || Valu
eTraits::needsDestruction; | 282 static const bool needsDestruction = KeyTraits::needsDestruction || Valu
eTraits::needsDestruction; |
| 288 template<typename U = void> | |
| 289 struct NeedsTracingLazily { | |
| 290 static const bool value = ShouldBeTraced<KeyTraits>::value || Should
BeTraced<ValueTraits>::value; | |
| 291 }; | |
| 292 static const WeakHandlingFlag weakHandlingFlag = (KeyTraits::weakHandlin
gFlag == WeakHandlingInCollections || ValueTraits::weakHandlingFlag == WeakHandl
ingInCollections) ? WeakHandlingInCollections : NoWeakHandlingInCollections; | 283 static const WeakHandlingFlag weakHandlingFlag = (KeyTraits::weakHandlin
gFlag == WeakHandlingInCollections || ValueTraits::weakHandlingFlag == WeakHandl
ingInCollections) ? WeakHandlingInCollections : NoWeakHandlingInCollections; |
| 293 | 284 |
| 294 static const unsigned minimumTableSize = KeyTraits::minimumTableSize; | 285 static const unsigned minimumTableSize = KeyTraits::minimumTableSize; |
| 295 | 286 |
| 296 static void constructDeletedValue(TraitType& slot, bool zeroValue) | 287 static void constructDeletedValue(TraitType& slot, bool zeroValue) |
| 297 { | 288 { |
| 298 KeyTraits::constructDeletedValue(slot.key, zeroValue); | 289 KeyTraits::constructDeletedValue(slot.key, zeroValue); |
| 299 // See similar code in this file for why we need to do this. | 290 // See similar code in this file for why we need to do this. |
| 300 if (zeroValue) | 291 if (zeroValue) |
| 301 memset(reinterpret_cast<void*>(&slot.value), 0, sizeof(slot.valu
e)); | 292 memset(reinterpret_cast<void*>(&slot.value), 0, sizeof(slot.valu
e)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 323 struct TraceInCollectionTrait; | 314 struct TraceInCollectionTrait; |
| 324 | 315 |
| 325 } // namespace WTF | 316 } // namespace WTF |
| 326 | 317 |
| 327 using WTF::HashTraits; | 318 using WTF::HashTraits; |
| 328 using WTF::PairHashTraits; | 319 using WTF::PairHashTraits; |
| 329 using WTF::NullableHashTraits; | 320 using WTF::NullableHashTraits; |
| 330 using WTF::SimpleClassHashTraits; | 321 using WTF::SimpleClassHashTraits; |
| 331 | 322 |
| 332 #endif // WTF_HashTraits_h | 323 #endif // WTF_HashTraits_h |
| OLD | NEW |