Changeset 170995 in webkit


Ignore:
Timestamp:
Jul 11, 2014 1:16:36 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

    r170968 r170995  
     12014-07-09  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-10  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/Source/WTF/wtf/HashTable.h

    r170774 r170995  
    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.
     
    11771180    }
    11781181
     1182    template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
     1183    inline HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::HashTable(HashTable&& other)
     1184#if CHECK_HASHTABLE_ITERATORS
     1185        : m_iterators(nullptr)
     1186        , m_mutex(std::make_unique<std::mutex>())
     1187#endif
     1188    {
     1189        other.invalidateIterators();
     1190
     1191        m_table = other.m_table;
     1192        m_tableSize = other.m_tableSize;
     1193        m_tableSizeMask = other.m_tableSizeMask;
     1194        m_keyCount = other.m_keyCount;
     1195        m_deletedCount = other.m_deletedCount;
     1196
     1197        other.m_table = nullptr;
     1198        other.m_tableSize = 0;
     1199        other.m_tableSizeMask = 0;
     1200        other.m_keyCount = 0;
     1201        other.m_deletedCount = 0;
     1202
     1203#if DUMP_HASHTABLE_STATS_PER_TABLE
     1204        m_stats = std::move(other.m_stats);
     1205#endif
     1206    }
     1207
     1208    template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
     1209    inline auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::operator=(HashTable&& other) -> HashTable&
     1210    {
     1211        invalidateIterators();
     1212        other.invalidateIterators();
     1213
     1214        m_table = other.m_table;
     1215        m_tableSize = other.m_tableSize;
     1216        m_tableSizeMask = other.m_tableSizeMask;
     1217        m_keyCount = other.m_keyCount;
     1218        m_deletedCount = other.m_deletedCount;
     1219
     1220        other.m_table = nullptr;
     1221        other.m_tableSize = 0;
     1222        other.m_tableSizeMask = 0;
     1223        other.m_keyCount = 0;
     1224        other.m_deletedCount = 0;
     1225
     1226#if DUMP_HASHTABLE_STATS_PER_TABLE
     1227        m_stats = std::move(other.m_stats);
     1228#endif
     1229
     1230        return *this;
     1231    }
     1232
    11791233#if !ASSERT_DISABLED
    11801234
Note: See TracChangeset for help on using the changeset viewer.