Skip to content

Commit 4c90863

Browse files
committed
Merge pull request godotengine#103698 from AThousandShips/fix_a_hash_map_construct
[Core] Fix `AHashMap` constructors reserving too few elements
2 parents a8bab92 + fad8134 commit 4c90863

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
@@ -665,7 +665,9 @@ class AHashMap {
665665
}
666666

667667
AHashMap(const HashMap<TKey, TValue> &p_other) {
668-
reserve(p_other.size());
668+
if (p_other.size() > get_capacity()) {
669+
reserve(p_other.size());
670+
}
669671
for (const KeyValue<TKey, TValue> &E : p_other) {
670672
uint32_t hash = _hash(E.key);
671673
_insert_element(E.key, E.value, hash);
@@ -703,7 +705,9 @@ class AHashMap {
703705
}
704706

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

0 commit comments

Comments
 (0)