mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 10:01:13 +09:00
AK: Reduce memory writes in HashTable destructor
This commit is contained in:
parent
d30c559774
commit
3efd4c105f
Notes:
sideshowbarker
2024-07-19 01:51:34 +09:00
Author: https://github.com/danopernis
Commit: 3efd4c105f
Pull-request: https://github.com/SerenityOS/serenity/pull/3788
1 changed files with 14 additions and 14 deletions
|
@ -89,7 +89,19 @@ class HashTable {
|
||||||
public:
|
public:
|
||||||
HashTable() { }
|
HashTable() { }
|
||||||
HashTable(size_t capacity) { rehash(capacity); }
|
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)
|
HashTable(const HashTable& other)
|
||||||
{
|
{
|
||||||
|
@ -188,19 +200,7 @@ public:
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
if (!m_buckets)
|
*this = HashTable();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSetResult set(T&& value)
|
HashSetResult set(T&& value)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue