Add dynamic array debug - resize on every item added, fix window bug
This commit is contained in:
@@ -358,6 +358,14 @@ Slice<T> GetSlice(Slice<T> &arr, int64_t first_index = 0, int64_t one_past_last_
|
||||
return result;
|
||||
}
|
||||
|
||||
// Make arrays resize on every item
|
||||
#define ARRAY_DEBUG 1
|
||||
#if ARRAY_DEBUG
|
||||
#define ARRAY_IF_DEBUG_ELSE(IF, ELSE) IF
|
||||
#else
|
||||
#define ARRAY_IF_DEBUG_ELSE(IF, ELSE) ELSE
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
struct Array {
|
||||
Allocator allocator;
|
||||
@@ -408,7 +416,7 @@ 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 * 2);
|
||||
int64_t new_size = ClampBottom((int64_t)16, arr->cap ARRAY_IF_DEBUG_ELSE(+1, *2));
|
||||
Reserve(arr, new_size);
|
||||
}
|
||||
}
|
||||
@@ -416,7 +424,7 @@ 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) * 2);
|
||||
int64_t new_size = ClampBottom((int64_t)16, (arr->cap + item_count) ARRAY_IF_DEBUG_ELSE(+1, *2));
|
||||
Reserve(arr, new_size);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user