mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
AK: Reduce memory writes in HashTable destructor
This commit is contained in:
parent
d30c559774
commit
3efd4c105f
|
@ -89,7 +89,19 @@ class HashTable {
|
|||
public:
|
||||
HashTable() { }
|
||||
HashTable(size_t capacity) { rehash(capacity); }
|
||||
~HashTable() { clear(); }
|
||||
|
||||
~HashTable()
|
||||
{
|
||||
if (!m_buckets)
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < m_capacity; ++i) {
|
||||
if (m_buckets[i].used)
|
||||
m_buckets[i].slot()->~T();
|
||||
}
|
||||
|
||||
kfree(m_buckets);
|
||||
}
|
||||
|
||||
HashTable(const HashTable& other)
|
||||
{
|
||||
|
@ -188,19 +200,7 @@ public:
|
|||
|
||||
void clear()
|
||||
{
|
||||
if (!m_buckets)
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < m_capacity; ++i) {
|
||||
if (m_buckets[i].used)
|
||||
m_buckets[i].slot()->~T();
|
||||
}
|
||||
|
||||
kfree(m_buckets);
|
||||
m_buckets = nullptr;
|
||||
m_capacity = 0;
|
||||
m_size = 0;
|
||||
m_deleted_count = 0;
|
||||
*this = HashTable();
|
||||
}
|
||||
|
||||
HashSetResult set(T&& value)
|
||||
|
|
Loading…
Reference in a new issue