Changeset 156507 in webkit


Ignore:
Timestamp:
Sep 26, 2013 3:37:20 PM (11 years ago)
Author:
andersca@apple.com
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:
Location:
trunk/Source/WTF
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r156505 r156507  
     12013-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
    1222013-09-26  Anders Carlsson  <andersca@apple.com>
    223
  • trunk/Source/WTF/wtf/HashTable.h

    r156496 r156507  
    10591059    void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::deallocateTable(ValueType* table, int size)
    10601060    {
    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();
    10661064        }
    10671065        fastFree(table);
  • trunk/Source/WTF/wtf/HashTraits.h

    r156429 r156507  
    4747    static const bool hasIsEmptyValueFunction = false;
    4848
    49     // The needsDestruction flag is used to optimize destruction and rehashing.
    50     static const bool needsDestruction = true;
    51 
    5249    // The starting table size. Can be overridden when we know beforehand that
    5350    // a hash table will have at least N entries.
     
    5855template<typename T> struct GenericHashTraitsBase<true, T> : GenericHashTraitsBase<false, T> {
    5956    static const bool emptyValueIsZero = true;
    60     static const bool needsDestruction = false;
    6157    static void constructDeletedValue(T& slot) { slot = static_cast<T>(-1); }
    6258    static bool isDeletedValue(T value) { return value == static_cast<T>(-1); }
     
    9187
    9288template<typename T> struct FloatHashTraits : GenericHashTraits<T> {
    93     static const bool needsDestruction = false;
    9489    static T emptyValue() { return std::numeric_limits<T>::infinity(); }
    9590    static void constructDeletedValue(T& slot) { slot = -std::numeric_limits<T>::infinity(); }
     
    10398template<typename T> struct UnsignedWithZeroKeyHashTraits : GenericHashTraits<T> {
    10499    static const bool emptyValueIsZero = false;
    105     static const bool needsDestruction = false;
    106100    static T emptyValue() { return std::numeric_limits<T>::max(); }
    107101    static void constructDeletedValue(T& slot) { slot = std::numeric_limits<T>::max() - 1; }
     
    111105template<typename P> struct HashTraits<P*> : GenericHashTraits<P*> {
    112106    static const bool emptyValueIsZero = true;
    113     static const bool needsDestruction = false;
    114107    static void constructDeletedValue(P*& slot) { slot = reinterpret_cast<P*>(-1); }
    115108    static bool isDeletedValue(P* value) { return value == reinterpret_cast<P*>(-1); }
     
    184177    static EmptyValueType emptyValue() { return std::make_pair(FirstTraits::emptyValue(), SecondTraits::emptyValue()); }
    185178
    186     static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
    187 
    188179    static const int minimumTableSize = FirstTraits::minimumTableSize;
    189180
     
    231222    static EmptyValueType emptyValue() { return KeyValuePair<typename KeyTraits::EmptyValueType, typename ValueTraits::EmptyValueType>(KeyTraits::emptyValue(), ValueTraits::emptyValue()); }
    232223
    233     static const bool needsDestruction = KeyTraits::needsDestruction || ValueTraits::needsDestruction;
    234 
    235224    static const int minimumTableSize = KeyTraits::minimumTableSize;
    236225
  • trunk/Source/WTF/wtf/Vector.h

    r156117 r156507  
    212212    static void destruct(T* begin, T* end)
    213213    {
    214         VectorDestructor<VectorTraits<T>::needsDestruction, T>::destruct(begin, end);
     214        VectorDestructor<!std::is_trivially_destructible<T>::value, T>::destruct(begin, end);
    215215    }
    216216
  • trunk/Source/WTF/wtf/VectorTraits.h

    r156128 r156507  
    4040    struct VectorTraitsBase<false, T>
    4141    {
    42         static const bool needsDestruction = true;
    4342        static const bool needsInitialization = true;
    4443        static const bool canInitializeWithMemset = false;
     
    5251    struct VectorTraitsBase<true, T>
    5352    {
    54         static const bool needsDestruction = false;
    5553        static const bool needsInitialization = false;
    5654        static const bool canInitializeWithMemset = false;
     
    9189        typedef VectorTraits<Second> SecondTraits;
    9290
    93         static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
    9491        static const bool needsInitialization = FirstTraits::needsInitialization || SecondTraits::needsInitialization;
    9592        static const bool canInitializeWithMemset = FirstTraits::canInitializeWithMemset && SecondTraits::canInitializeWithMemset;
Note: See TracChangeset for help on using the changeset viewer.