Title: [171262] trunk/Source/WTF
Revision
171262
Author
[email protected]
Date
2014-07-19 03:10:50 -0700 (Sat, 19 Jul 2014)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (171261 => 171262)


--- trunk/Source/WTF/ChangeLog	2014-07-19 10:08:55 UTC (rev 171261)
+++ trunk/Source/WTF/ChangeLog	2014-07-19 10:10:50 UTC (rev 171262)
@@ -1,3 +1,17 @@
+2014-07-19  Zan Dobersek  <[email protected]>
+
+        [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):
+
 2014-07-15  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r171107.

Modified: trunk/Source/WTF/wtf/HashTable.h (171261 => 171262)


--- trunk/Source/WTF/wtf/HashTable.h	2014-07-19 10:08:55 UTC (rev 171261)
+++ trunk/Source/WTF/wtf/HashTable.h	2014-07-19 10:10:50 UTC (rev 171262)
@@ -360,6 +360,9 @@
         void swap(HashTable&);
         HashTable& operator=(const HashTable&);
 
+        HashTable(HashTable&&);
+        HashTable& operator=(HashTable&&);
+
         // When the hash table is empty, just return the same iterator for end as for begin.
         // This is more efficient because we don't have to skip all the empty and deleted
         // buckets, and iterating an empty table is a common case that's worth optimizing.
@@ -1200,6 +1203,59 @@
         return *this;
     }
 
+    template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
+    inline HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::HashTable(HashTable&& other)
+#if CHECK_HASHTABLE_ITERATORS
+        : m_iterators(nullptr)
+        , m_mutex(std::make_unique<std::mutex>())
+#endif
+    {
+        other.invalidateIterators();
+
+        m_table = other.m_table;
+        m_tableSize = other.m_tableSize;
+        m_tableSizeMask = other.m_tableSizeMask;
+        m_keyCount = other.m_keyCount;
+        m_deletedCount = other.m_deletedCount;
+
+        other.m_table = nullptr;
+        other.m_tableSize = 0;
+        other.m_tableSizeMask = 0;
+        other.m_keyCount = 0;
+        other.m_deletedCount = 0;
+
+#if DUMP_HASHTABLE_STATS_PER_TABLE
+        m_stats = std::move(other.m_stats);
+        other.m_stats = nullptr;
+#endif
+    }
+
+    template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
+    inline auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::operator=(HashTable&& other) -> HashTable&
+    {
+        invalidateIterators();
+        other.invalidateIterators();
+
+        m_table = other.m_table;
+        m_tableSize = other.m_tableSize;
+        m_tableSizeMask = other.m_tableSizeMask;
+        m_keyCount = other.m_keyCount;
+        m_deletedCount = other.m_deletedCount;
+
+        other.m_table = nullptr;
+        other.m_tableSize = 0;
+        other.m_tableSizeMask = 0;
+        other.m_keyCount = 0;
+        other.m_deletedCount = 0;
+
+#if DUMP_HASHTABLE_STATS_PER_TABLE
+        m_stats = std::move(other.m_stats);
+        other.m_stats = nullptr;
+#endif
+
+        return *this;
+    }
+
 #if !ASSERT_DISABLED
 
     template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to