Smoke test: In collections, log an error if reserve() is called with a number smaller than the current size. Don't log an error if it is called with a number smaller than the current capacity.

This commit is contained in:
Lukas Tenbrink
2025-04-11 14:49:49 +02:00
parent 1696ab0cb6
commit 7c37188ca1
7 changed files with 16 additions and 13 deletions

View File

@@ -432,6 +432,7 @@ public:
// Reserves space for a number of elements, useful to avoid many resizes and rehashes.
// If adding a known (possibly large) number of elements at once, must be larger than old capacity.
void reserve(uint32_t p_new_capacity) {
ERR_FAIL_COND_MSG(p_new_capacity < size(), "reserve() called with a capacity smaller than the current size. This is likely a mistake.");
uint32_t new_index = capacity_index;
while (hash_table_size_primes[new_index] < p_new_capacity) {