Changeset 156507 in webkit
- Timestamp:
- Sep 26, 2013 3:37:20 PM (11 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r156505 r156507 1 2013-09-26 Anders Carlsson <andersca@apple.com> 2 3 Remove needsDestruction from vector and hash traits 4 https://bugs.webkit.org/show_bug.cgi?id=121983 5 6 Reviewed by Sam Weinig. 7 8 For Vector, use std::is_trivially_destructible to determine whether to call the destructor. 9 For HashTable, always call the destructor; if it is trivial then no code will be generated for it and the loops will be folded away. 10 11 Removing this does break the ability to store objects with non-trivial destructors in vectors and hash maps 12 and have their destructors not be called when removed, but we've never used this feature in WebKit so the extra 13 code complexity is not worth it. 14 15 * wtf/HashTable.h: 16 (WTF::::deallocateTable): 17 * wtf/HashTraits.h: 18 * wtf/Vector.h: 19 (WTF::VectorTypeOperations::destruct): 20 * wtf/VectorTraits.h: 21 1 22 2013-09-26 Anders Carlsson <andersca@apple.com> 2 23 -
trunk/Source/WTF/wtf/HashTable.h
r156496 r156507 1059 1059 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::deallocateTable(ValueType* table, int size) 1060 1060 { 1061 if (Traits::needsDestruction) { 1062 for (int i = 0; i < size; ++i) { 1063 if (!isDeletedBucket(table[i])) 1064 table[i].~ValueType(); 1065 } 1061 for (int i = 0; i < size; ++i) { 1062 if (!isDeletedBucket(table[i])) 1063 table[i].~ValueType(); 1066 1064 } 1067 1065 fastFree(table); -
trunk/Source/WTF/wtf/HashTraits.h
r156429 r156507 47 47 static const bool hasIsEmptyValueFunction = false; 48 48 49 // The needsDestruction flag is used to optimize destruction and rehashing.50 static const bool needsDestruction = true;51 52 49 // The starting table size. Can be overridden when we know beforehand that 53 50 // a hash table will have at least N entries. … … 58 55 template<typename T> struct GenericHashTraitsBase<true, T> : GenericHashTraitsBase<false, T> { 59 56 static const bool emptyValueIsZero = true; 60 static const bool needsDestruction = false;61 57 static void constructDeletedValue(T& slot) { slot = static_cast<T>(-1); } 62 58 static bool isDeletedValue(T value) { return value == static_cast<T>(-1); } … … 91 87 92 88 template<typename T> struct FloatHashTraits : GenericHashTraits<T> { 93 static const bool needsDestruction = false;94 89 static T emptyValue() { return std::numeric_limits<T>::infinity(); } 95 90 static void constructDeletedValue(T& slot) { slot = -std::numeric_limits<T>::infinity(); } … … 103 98 template<typename T> struct UnsignedWithZeroKeyHashTraits : GenericHashTraits<T> { 104 99 static const bool emptyValueIsZero = false; 105 static const bool needsDestruction = false;106 100 static T emptyValue() { return std::numeric_limits<T>::max(); } 107 101 static void constructDeletedValue(T& slot) { slot = std::numeric_limits<T>::max() - 1; } … … 111 105 template<typename P> struct HashTraits<P*> : GenericHashTraits<P*> { 112 106 static const bool emptyValueIsZero = true; 113 static const bool needsDestruction = false;114 107 static void constructDeletedValue(P*& slot) { slot = reinterpret_cast<P*>(-1); } 115 108 static bool isDeletedValue(P* value) { return value == reinterpret_cast<P*>(-1); } … … 184 177 static EmptyValueType emptyValue() { return std::make_pair(FirstTraits::emptyValue(), SecondTraits::emptyValue()); } 185 178 186 static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;187 188 179 static const int minimumTableSize = FirstTraits::minimumTableSize; 189 180 … … 231 222 static EmptyValueType emptyValue() { return KeyValuePair<typename KeyTraits::EmptyValueType, typename ValueTraits::EmptyValueType>(KeyTraits::emptyValue(), ValueTraits::emptyValue()); } 232 223 233 static const bool needsDestruction = KeyTraits::needsDestruction || ValueTraits::needsDestruction;234 235 224 static const int minimumTableSize = KeyTraits::minimumTableSize; 236 225 -
trunk/Source/WTF/wtf/Vector.h
r156117 r156507 212 212 static void destruct(T* begin, T* end) 213 213 { 214 VectorDestructor< VectorTraits<T>::needsDestruction, T>::destruct(begin, end);214 VectorDestructor<!std::is_trivially_destructible<T>::value, T>::destruct(begin, end); 215 215 } 216 216 -
trunk/Source/WTF/wtf/VectorTraits.h
r156128 r156507 40 40 struct VectorTraitsBase<false, T> 41 41 { 42 static const bool needsDestruction = true;43 42 static const bool needsInitialization = true; 44 43 static const bool canInitializeWithMemset = false; … … 52 51 struct VectorTraitsBase<true, T> 53 52 { 54 static const bool needsDestruction = false;55 53 static const bool needsInitialization = false; 56 54 static const bool canInitializeWithMemset = false; … … 91 89 typedef VectorTraits<Second> SecondTraits; 92 90 93 static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;94 91 static const bool needsInitialization = FirstTraits::needsInitialization || SecondTraits::needsInitialization; 95 92 static const bool canInitializeWithMemset = FirstTraits::canInitializeWithMemset && SecondTraits::canInitializeWithMemset;
Note: See TracChangeset
for help on using the changeset viewer.