mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Implement HashTable assignment in terms of swap
This commit is contained in:
parent
7f3f63dd92
commit
d30c559774
Notes:
sideshowbarker
2024-07-19 01:51:37 +09:00
Author: https://github.com/danopernis Commit: https://github.com/SerenityOS/serenity/commit/d30c5597749 Pull-request: https://github.com/SerenityOS/serenity/pull/3788
1 changed files with 5 additions and 15 deletions
|
@ -100,16 +100,12 @@ public:
|
||||||
|
|
||||||
HashTable& operator=(const HashTable& other)
|
HashTable& operator=(const HashTable& other)
|
||||||
{
|
{
|
||||||
if (this != &other) {
|
HashTable temporary(other);
|
||||||
clear();
|
swap(*this, temporary);
|
||||||
rehash(other.capacity());
|
|
||||||
for (auto& it : other)
|
|
||||||
set(it);
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashTable(HashTable&& other)
|
HashTable(HashTable&& other) noexcept
|
||||||
: m_buckets(other.m_buckets)
|
: m_buckets(other.m_buckets)
|
||||||
, m_size(other.m_size)
|
, m_size(other.m_size)
|
||||||
, m_capacity(other.m_capacity)
|
, m_capacity(other.m_capacity)
|
||||||
|
@ -121,15 +117,9 @@ public:
|
||||||
other.m_buckets = nullptr;
|
other.m_buckets = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashTable& operator=(HashTable&& other)
|
HashTable& operator=(HashTable&& other) noexcept
|
||||||
{
|
{
|
||||||
if (this != &other) {
|
swap(*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);
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue