From 235926dadb686589f0b5480162c3ab929159e570 Mon Sep 17 00:00:00 2001 From: navewindre Date: Wed, 10 Sep 2025 12:25:00 +0200 Subject: unfuck --- src/util/allocator.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/util/allocator.h') diff --git a/src/util/allocator.h b/src/util/allocator.h index ee0ddd8..7927b9c 100644 --- a/src/util/allocator.h +++ b/src/util/allocator.h @@ -161,6 +161,18 @@ struct LIST { return &data[size - 1]; } + void resize( U32 size ) { + if( size > capacity ) + reserve( size * 2 ); + + if( size < capacity ) { + for( U32 i = size; i < capacity; ++i ) + data[i] = T(); + } + + this->size = size; + } + // does not call copy constructors, raw memcpy void emplace_list( const LIST& list ) { if( !list.size ) -- cgit v1.2.3 From e3de3ba5162f7ddd5005911124d4333e140fd984 Mon Sep 17 00:00:00 2001 From: navewindre Date: Thu, 27 Nov 2025 17:19:02 +0100 Subject: bunch o stuff --- src/util/allocator.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/util/allocator.h') diff --git a/src/util/allocator.h b/src/util/allocator.h index 7927b9c..27b21c0 100644 --- a/src/util/allocator.h +++ b/src/util/allocator.h @@ -165,8 +165,12 @@ struct LIST { if( size > capacity ) reserve( size * 2 ); - if( size < capacity ) { - for( U32 i = size; i < capacity; ++i ) + if( size < capacity / 4 ) + shrink(); + + if( this->size < size ) { + memset( &data[this->size], 0, sizeof(T) * (size - this->size) ); + for( U32 i = this->size; i < size; ++i ) data[i] = T(); } @@ -262,6 +266,16 @@ struct LIST { return -1; } + I32 idx_of( const T* what ) { + for( U32 i = 0; i < size; ++i ) { + if( &data[i] == what ) { + return i; + } + } + + return -1; + } + I32 idx_where( ON_SEARCH_FN what ) { for( U32 i = 0; i < size; ++i ) { if( what( &data[i] ) ) { -- cgit v1.2.3