diff --git a/core/templates/a_hash_map.h b/core/templates/a_hash_map.h index 03089f093a3..e315a1406bd 100644 --- a/core/templates/a_hash_map.h +++ b/core/templates/a_hash_map.h @@ -666,7 +666,9 @@ public: } AHashMap(const HashMap &p_other) { - reserve(p_other.size()); + if (p_other.size() > get_capacity()) { + reserve(p_other.size()); + } for (const KeyValue &E : p_other) { uint32_t hash = _hash(E.key); _insert_element(E.key, E.value, hash); @@ -704,7 +706,9 @@ public: } AHashMap(std::initializer_list> p_init) { - reserve(p_init.size()); + if (p_init.size() > get_capacity()) { + reserve(p_init.size()); + } for (const KeyValue &E : p_init) { insert(E.key, E.value); }