Title: [156507] trunk/Source/WTF
Revision
156507
Author
[email protected]
Date
2013-09-26 15:37:20 -0700 (Thu, 26 Sep 2013)

Log Message

Remove needsDestruction from vector and hash traits
https://bugs.webkit.org/show_bug.cgi?id=121983

Reviewed by Sam Weinig.

For Vector, use std::is_trivially_destructible to determine whether to call the destructor.
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.

Removing this does break the ability to store objects with non-trivial destructors in vectors and hash maps
and have their destructors not be called when removed, but we've never used this feature in WebKit so the extra
code complexity is not worth it.

* wtf/HashTable.h:
(WTF::::deallocateTable):
* wtf/HashTraits.h:
* wtf/Vector.h:
(WTF::VectorTypeOperations::destruct):
* wtf/VectorTraits.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (156506 => 156507)


--- trunk/Source/WTF/ChangeLog	2013-09-26 22:29:07 UTC (rev 156506)
+++ trunk/Source/WTF/ChangeLog	2013-09-26 22:37:20 UTC (rev 156507)
@@ -1,5 +1,26 @@
 2013-09-26  Anders Carlsson  <[email protected]>
 
+        Remove needsDestruction from vector and hash traits
+        https://bugs.webkit.org/show_bug.cgi?id=121983
+
+        Reviewed by Sam Weinig.
+
+        For Vector, use std::is_trivially_destructible to determine whether to call the destructor.
+        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. 
+
+        Removing this does break the ability to store objects with non-trivial destructors in vectors and hash maps
+        and have their destructors not be called when removed, but we've never used this feature in WebKit so the extra
+        code complexity is not worth it.
+
+        * wtf/HashTable.h:
+        (WTF::::deallocateTable):
+        * wtf/HashTraits.h:
+        * wtf/Vector.h:
+        (WTF::VectorTypeOperations::destruct):
+        * wtf/VectorTraits.h:
+
+2013-09-26  Anders Carlsson  <[email protected]>
+
         Build fixes.
 
         Fix a paste-o.

Modified: trunk/Source/WTF/wtf/HashTable.h (156506 => 156507)


--- trunk/Source/WTF/wtf/HashTable.h	2013-09-26 22:29:07 UTC (rev 156506)
+++ trunk/Source/WTF/wtf/HashTable.h	2013-09-26 22:37:20 UTC (rev 156507)
@@ -1058,11 +1058,9 @@
     template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
     void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::deallocateTable(ValueType* table, int size)
     {
-        if (Traits::needsDestruction) {
-            for (int i = 0; i < size; ++i) {
-                if (!isDeletedBucket(table[i]))
-                    table[i].~ValueType();
-            }
+        for (int i = 0; i < size; ++i) {
+            if (!isDeletedBucket(table[i]))
+                table[i].~ValueType();
         }
         fastFree(table);
     }

Modified: trunk/Source/WTF/wtf/HashTraits.h (156506 => 156507)


--- trunk/Source/WTF/wtf/HashTraits.h	2013-09-26 22:29:07 UTC (rev 156506)
+++ trunk/Source/WTF/wtf/HashTraits.h	2013-09-26 22:37:20 UTC (rev 156507)
@@ -46,9 +46,6 @@
     // for cases like String that need them.
     static const bool hasIsEmptyValueFunction = false;
 
-    // The needsDestruction flag is used to optimize destruction and rehashing.
-    static const bool needsDestruction = true;
-
     // The starting table size. Can be overridden when we know beforehand that
     // a hash table will have at least N entries.
     static const int minimumTableSize = 8;
@@ -57,7 +54,6 @@
 // Default integer traits disallow both 0 and -1 as keys (max value instead of -1 for unsigned).
 template<typename T> struct GenericHashTraitsBase<true, T> : GenericHashTraitsBase<false, T> {
     static const bool emptyValueIsZero = true;
-    static const bool needsDestruction = false;
     static void constructDeletedValue(T& slot) { slot = static_cast<T>(-1); }
     static bool isDeletedValue(T value) { return value == static_cast<T>(-1); }
 };
@@ -90,7 +86,6 @@
 template<typename T> struct HashTraits : GenericHashTraits<T> { };
 
 template<typename T> struct FloatHashTraits : GenericHashTraits<T> {
-    static const bool needsDestruction = false;
     static T emptyValue() { return std::numeric_limits<T>::infinity(); }
     static void constructDeletedValue(T& slot) { slot = -std::numeric_limits<T>::infinity(); }
     static bool isDeletedValue(T value) { return value == -std::numeric_limits<T>::infinity(); }
@@ -102,7 +97,6 @@
 // Default unsigned traits disallow both 0 and max as keys -- use these traits to allow zero and disallow max - 1.
 template<typename T> struct UnsignedWithZeroKeyHashTraits : GenericHashTraits<T> {
     static const bool emptyValueIsZero = false;
-    static const bool needsDestruction = false;
     static T emptyValue() { return std::numeric_limits<T>::max(); }
     static void constructDeletedValue(T& slot) { slot = std::numeric_limits<T>::max() - 1; }
     static bool isDeletedValue(T value) { return value == std::numeric_limits<T>::max() - 1; }
@@ -110,7 +104,6 @@
 
 template<typename P> struct HashTraits<P*> : GenericHashTraits<P*> {
     static const bool emptyValueIsZero = true;
-    static const bool needsDestruction = false;
     static void constructDeletedValue(P*& slot) { slot = reinterpret_cast<P*>(-1); }
     static bool isDeletedValue(P* value) { return value == reinterpret_cast<P*>(-1); }
 };
@@ -183,8 +176,6 @@
     static const bool emptyValueIsZero = FirstTraits::emptyValueIsZero && SecondTraits::emptyValueIsZero;
     static EmptyValueType emptyValue() { return std::make_pair(FirstTraits::emptyValue(), SecondTraits::emptyValue()); }
 
-    static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
-
     static const int minimumTableSize = FirstTraits::minimumTableSize;
 
     static void constructDeletedValue(TraitType& slot) { FirstTraits::constructDeletedValue(slot.first); }
@@ -230,8 +221,6 @@
     static const bool emptyValueIsZero = KeyTraits::emptyValueIsZero && ValueTraits::emptyValueIsZero;
     static EmptyValueType emptyValue() { return KeyValuePair<typename KeyTraits::EmptyValueType, typename ValueTraits::EmptyValueType>(KeyTraits::emptyValue(), ValueTraits::emptyValue()); }
 
-    static const bool needsDestruction = KeyTraits::needsDestruction || ValueTraits::needsDestruction;
-
     static const int minimumTableSize = KeyTraits::minimumTableSize;
 
     static void constructDeletedValue(TraitType& slot) { KeyTraits::constructDeletedValue(slot.key); }

Modified: trunk/Source/WTF/wtf/Vector.h (156506 => 156507)


--- trunk/Source/WTF/wtf/Vector.h	2013-09-26 22:29:07 UTC (rev 156506)
+++ trunk/Source/WTF/wtf/Vector.h	2013-09-26 22:37:20 UTC (rev 156507)
@@ -211,7 +211,7 @@
 {
     static void destruct(T* begin, T* end)
     {
-        VectorDestructor<VectorTraits<T>::needsDestruction, T>::destruct(begin, end);
+        VectorDestructor<!std::is_trivially_destructible<T>::value, T>::destruct(begin, end);
     }
 
     static void initialize(T* begin, T* end)

Modified: trunk/Source/WTF/wtf/VectorTraits.h (156506 => 156507)


--- trunk/Source/WTF/wtf/VectorTraits.h	2013-09-26 22:29:07 UTC (rev 156506)
+++ trunk/Source/WTF/wtf/VectorTraits.h	2013-09-26 22:37:20 UTC (rev 156507)
@@ -39,7 +39,6 @@
     template<typename T>
     struct VectorTraitsBase<false, T>
     {
-        static const bool needsDestruction = true;
         static const bool needsInitialization = true;
         static const bool canInitializeWithMemset = false;
         static const bool canMoveWithMemcpy = false;
@@ -51,7 +50,6 @@
     template<typename T>
     struct VectorTraitsBase<true, T>
     {
-        static const bool needsDestruction = false;
         static const bool needsInitialization = false;
         static const bool canInitializeWithMemset = false;
         static const bool canMoveWithMemcpy = true;
@@ -90,7 +88,6 @@
         typedef VectorTraits<First> FirstTraits;
         typedef VectorTraits<Second> SecondTraits;
 
-        static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
         static const bool needsInitialization = FirstTraits::needsInitialization || SecondTraits::needsInitialization;
         static const bool canInitializeWithMemset = FirstTraits::canInitializeWithMemset && SecondTraits::canInitializeWithMemset;
         static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy && SecondTraits::canMoveWithMemcpy;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to