Fixing array resize bugs
This commit is contained in:
@@ -359,7 +359,7 @@ Slice<T> GetSlice(Slice<T> &arr, int64_t first_index = 0, int64_t one_past_last_
|
||||
}
|
||||
|
||||
// Make arrays resize on every item
|
||||
#define ARRAY_DEBUG 1
|
||||
#define ARRAY_DEBUG 0
|
||||
#if ARRAY_DEBUG
|
||||
#define ARRAY_IF_DEBUG_ELSE(IF, ELSE) IF
|
||||
#else
|
||||
@@ -416,7 +416,8 @@ void Reserve(Array<T> *arr, int64_t size) {
|
||||
template <class T>
|
||||
void TryGrowing(Array<T> *arr) {
|
||||
if (arr->len + 1 > arr->cap) {
|
||||
int64_t new_size = ClampBottom((int64_t)16, arr->cap ARRAY_IF_DEBUG_ELSE(+1, *2));
|
||||
int64_t initial_size = (int64_t)ARRAY_IF_DEBUG_ELSE(1, 16);
|
||||
int64_t new_size = ClampBottom(initial_size, arr->cap ARRAY_IF_DEBUG_ELSE(+1, *2));
|
||||
Reserve(arr, new_size);
|
||||
}
|
||||
}
|
||||
@@ -424,7 +425,8 @@ void TryGrowing(Array<T> *arr) {
|
||||
template <class T>
|
||||
void TryGrowing(Array<T> *arr, int64_t item_count) {
|
||||
if (arr->len + item_count > arr->cap) {
|
||||
int64_t new_size = ClampBottom((int64_t)16, (arr->cap + item_count) ARRAY_IF_DEBUG_ELSE(+1, *2));
|
||||
int64_t initial_size = (int64_t)ARRAY_IF_DEBUG_ELSE(1, 16);
|
||||
int64_t new_size = ClampBottom(initial_size, (arr->cap + item_count) ARRAY_IF_DEBUG_ELSE(+1, *2));
|
||||
Reserve(arr, new_size);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user