summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}