summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDano Perniš <danopernis@gmail.com>2020-10-17 15:08:09 +0200
committerAndreas Kling <kling@serenityos.org>2020-10-18 14:44:23 +0200
commitd30c5597749923cfceef02bb515b240f099830b6 (patch)
treede70f356854b3e79f625c9b911f0586d42f865ce
parent7f3f63dd923cdd616196a3b6504ec6b170257467 (diff)
downloadserenity-d30c5597749923cfceef02bb515b240f099830b6.zip
AK: Implement HashTable assignment in terms of swap
-rw-r--r--AK/HashTable.h20
1 files changed, 5 insertions, 15 deletions
diff --git a/AK/HashTable.h b/AK/HashTable.h
index 63b37b04cc..3b8ed100f4 100644
--- a/AK/HashTable.h
+++ b/AK/HashTable.h
@@ -100,16 +100,12 @@ public:
HashTable& operator=(const HashTable& other)
{
- if (this != &other) {
- clear();
- rehash(other.capacity());
- for (auto& it : other)
- set(it);
- }
+ HashTable temporary(other);
+ swap(*this, temporary);
return *this;
}
- HashTable(HashTable&& other)
+ HashTable(HashTable&& other) noexcept
: m_buckets(other.m_buckets)
, m_size(other.m_size)
, m_capacity(other.m_capacity)
@@ -121,15 +117,9 @@ public:
other.m_buckets = nullptr;
}
- HashTable& operator=(HashTable&& other)
+ HashTable& operator=(HashTable&& other) noexcept
{
- if (this != &other) {
- clear();
- m_buckets = exchange(other.m_buckets, nullptr);
- m_size = exchange(other.m_size, 0);
- m_capacity = exchange(other.m_capacity, 0);
- m_deleted_count = exchange(other.m_deleted_count, 0);
- }
+ swap(*this, other);
return *this;
}