mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Change "reserve called with a capacity smaller than the current size" error message to a verbose message.
This commit is contained in:
parent
3d91a48298
commit
c6f57c7a55
6 changed files with 20 additions and 6 deletions
|
|
@ -402,13 +402,15 @@ 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.");
|
||||
if (_elements == nullptr) {
|
||||
_capacity_mask = MAX(4u, p_new_capacity);
|
||||
_capacity_mask = next_power_of_2(_capacity_mask) - 1;
|
||||
return; // Unallocated yet.
|
||||
}
|
||||
if (p_new_capacity <= get_capacity()) {
|
||||
if (p_new_capacity < size()) {
|
||||
WARN_VERBOSE("reserve() called with a capacity smaller than the current size. This is likely a mistake.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
_resize_and_rehash(p_new_capacity);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/os/memory.h"
|
||||
#include "core/string/print_string.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
#include "core/templates/pair.h"
|
||||
#include "core/templates/sort_list.h"
|
||||
|
|
@ -398,7 +399,6 @@ 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_idx = _capacity_idx;
|
||||
|
||||
while (hash_table_size_primes[new_idx] < p_new_capacity) {
|
||||
|
|
@ -407,6 +407,9 @@ public:
|
|||
}
|
||||
|
||||
if (new_idx == _capacity_idx) {
|
||||
if (p_new_capacity < _size) {
|
||||
WARN_VERBOSE("reserve() called with a capacity smaller than the current size. This is likely a mistake.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/os/memory.h"
|
||||
#include "core/string/print_string.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
|
||||
/**
|
||||
|
|
@ -298,7 +299,6 @@ 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_capacity_idx = _capacity_idx;
|
||||
|
||||
while (hash_table_size_primes[new_capacity_idx] < p_new_capacity) {
|
||||
|
|
@ -307,6 +307,9 @@ public:
|
|||
}
|
||||
|
||||
if (new_capacity_idx == _capacity_idx) {
|
||||
if (p_new_capacity < _size) {
|
||||
WARN_VERBOSE("reserve() called with a capacity smaller than the current size. This is likely a mistake.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/os/memory.h"
|
||||
#include "core/string/print_string.h"
|
||||
#include "core/templates/sort_array.h"
|
||||
#include "core/templates/vector.h"
|
||||
|
||||
|
|
@ -161,7 +162,6 @@ public:
|
|||
_FORCE_INLINE_ bool is_empty() const { return count == 0; }
|
||||
_FORCE_INLINE_ U get_capacity() const { return capacity; }
|
||||
void reserve(U p_size) {
|
||||
ERR_FAIL_COND_MSG(p_size < size(), "reserve() called with a capacity smaller than the current size. This is likely a mistake.");
|
||||
if (p_size > capacity) {
|
||||
if (tight) {
|
||||
capacity = p_size;
|
||||
|
|
@ -173,6 +173,8 @@ public:
|
|||
}
|
||||
data = (T *)memrealloc(data, capacity * sizeof(T));
|
||||
CRASH_COND_MSG(!data, "Out of memory");
|
||||
} else if (p_size < count) {
|
||||
WARN_VERBOSE("reserve() called with a capacity smaller than the current size. This is likely a mistake.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue