Changeset 171262 in webkit


Ignore:
Timestamp:
Jul 19, 2014 3:10:50 AM (10 years ago)
Author:
zandobersek@gmail.com
Message:

[WTF] Add the move constructor, move assignment operator for HashTable
https://bugs.webkit.org/show_bug.cgi?id=130772

Reviewed by Darin Adler.

HashTable has both copy constructor and copy assignment operator, meaning that the move constructor
and move assignment operator are implicitly deleted. This patch defines both to avoid unnecessary
copies when moves can be performed.

  • wtf/HashTable.h:

(WTF::KeyTraits>::HashTable):

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r171131 r171262  
     12014-07-19  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [WTF] Add the move constructor, move assignment operator for HashTable
     4        https://bugs.webkit.org/show_bug.cgi?id=130772
     5
     6        Reviewed by Darin Adler.
     7
     8        HashTable has both copy constructor and copy assignment operator, meaning that the move constructor
     9        and move assignment operator are implicitly deleted. This patch defines both to avoid unnecessary
     10        copies when moves can be performed.
     11
     12        * wtf/HashTable.h:
     13        (WTF::KeyTraits>::HashTable):
     14
    1152014-07-15  Commit Queue  <commit-queue@webkit.org>
    216
  • trunk/Source/WTF/wtf/HashTable.h

    r171049 r171262  
    360360        void swap(HashTable&);
    361361        HashTable& operator=(const HashTable&);
     362
     363        HashTable(HashTable&&);
     364        HashTable& operator=(HashTable&&);
    362365
    363366        // When the hash table is empty, just return the same iterator for end as for begin.
     
    12011204    }
    12021205
     1206    template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
     1207    inline HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::HashTable(HashTable&& other)
     1208#if CHECK_HASHTABLE_ITERATORS
     1209        : m_iterators(nullptr)
     1210        , m_mutex(std::make_unique<std::mutex>())
     1211#endif
     1212    {
     1213        other.invalidateIterators();
     1214
     1215        m_table = other.m_table;
     1216        m_tableSize = other.m_tableSize;
     1217        m_tableSizeMask = other.m_tableSizeMask;
     1218        m_keyCount = other.m_keyCount;
     1219        m_deletedCount = other.m_deletedCount;
     1220
     1221        other.m_table = nullptr;
     1222        other.m_tableSize = 0;
     1223        other.m_tableSizeMask = 0;
     1224        other.m_keyCount = 0;
     1225        other.m_deletedCount = 0;
     1226
     1227#if DUMP_HASHTABLE_STATS_PER_TABLE
     1228        m_stats = std::move(other.m_stats);
     1229        other.m_stats = nullptr;
     1230#endif
     1231    }
     1232
     1233    template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
     1234    inline auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::operator=(HashTable&& other) -> HashTable&
     1235    {
     1236        invalidateIterators();
     1237        other.invalidateIterators();
     1238
     1239        m_table = other.m_table;
     1240        m_tableSize = other.m_tableSize;
     1241        m_tableSizeMask = other.m_tableSizeMask;
     1242        m_keyCount = other.m_keyCount;
     1243        m_deletedCount = other.m_deletedCount;
     1244
     1245        other.m_table = nullptr;
     1246        other.m_tableSize = 0;
     1247        other.m_tableSizeMask = 0;
     1248        other.m_keyCount = 0;
     1249        other.m_deletedCount = 0;
     1250
     1251#if DUMP_HASHTABLE_STATS_PER_TABLE
     1252        m_stats = std::move(other.m_stats);
     1253        other.m_stats = nullptr;
     1254#endif
     1255
     1256        return *this;
     1257    }
     1258
    12031259#if !ASSERT_DISABLED
    12041260
Note: See TracChangeset for help on using the changeset viewer.