From 0babb2ab02fcd1f88399ae1c5da0038c3d0d145f Mon Sep 17 00:00:00 2001 From: Yufeng Ying Date: Tue, 13 May 2025 21:44:39 +0800 Subject: [PATCH] Optimize HashMap size for zero-sized Allocators. --- core/templates/hash_map.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/templates/hash_map.h b/core/templates/hash_map.h index 53a76fcf48..ef0ca33046 100644 --- a/core/templates/hash_map.h +++ b/core/templates/hash_map.h @@ -66,14 +66,13 @@ template , typename Allocator = DefaultTypedAllocator>> -class HashMap { +class HashMap : private Allocator { public: static constexpr uint32_t MIN_CAPACITY_INDEX = 2; // Use a prime. static constexpr float MAX_OCCUPANCY = 0.75; static constexpr uint32_t EMPTY_HASH = 0; private: - Allocator element_alloc; HashMapElement **elements = nullptr; uint32_t *hashes = nullptr; HashMapElement *head_element = nullptr; @@ -214,7 +213,7 @@ private: _resize_and_rehash(capacity_index + 1); } - HashMapElement *elem = element_alloc.new_allocation(HashMapElement(p_key, p_value)); + HashMapElement *elem = Allocator::new_allocation(HashMapElement(p_key, p_value)); if (tail_element == nullptr) { head_element = elem; @@ -254,7 +253,7 @@ public: } hashes[i] = EMPTY_HASH; - element_alloc.delete_allocation(elements[i]); + Allocator::delete_allocation(elements[i]); elements[i] = nullptr; } @@ -379,7 +378,7 @@ public: elements[pos]->next->prev = elements[pos]->prev; } - element_alloc.delete_allocation(elements[pos]); + Allocator::delete_allocation(elements[pos]); elements[pos] = nullptr; num_elements--;