Skip to content

Commit fad8134

Browse files
[Core] Fix AHashMap constructors reserving too few elements
1 parent 134da37 commit fad8134

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

core/templates/a_hash_map.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,9 @@ class AHashMap {
666666
}
667667

668668
AHashMap(const HashMap<TKey, TValue> &p_other) {
669-
reserve(p_other.size());
669+
if (p_other.size() > get_capacity()) {
670+
reserve(p_other.size());
671+
}
670672
for (const KeyValue<TKey, TValue> &E : p_other) {
671673
uint32_t hash = _hash(E.key);
672674
_insert_element(E.key, E.value, hash);
@@ -704,7 +706,9 @@ class AHashMap {
704706
}
705707

706708
AHashMap(std::initializer_list<KeyValue<TKey, TValue>> p_init) {
707-
reserve(p_init.size());
709+
if (p_init.size() > get_capacity()) {
710+
reserve(p_init.size());
711+
}
708712
for (const KeyValue<TKey, TValue> &E : p_init) {
709713
insert(E.key, E.value);
710714
}

0 commit comments

Comments
 (0)