diff options
| author | aura <nw@moneybot.cc> | 2026-03-10 01:35:50 +0100 |
|---|---|---|
| committer | aura <nw@moneybot.cc> | 2026-03-10 01:35:50 +0100 |
| commit | 8329d42d3e592f4cd42cdfa586e2325ddc76c898 (patch) | |
| tree | dec7e2a733bfc6b6384936c1f3ed067a42b59bb9 /src/util/allocator.h | |
| parent | 8ae8c85e9d3806cdb726e07f37e1b49484c5c48e (diff) | |
perf profiler, simplify 2d render, string struct, many small things
Diffstat (limited to 'src/util/allocator.h')
| -rw-r--r-- | src/util/allocator.h | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/util/allocator.h b/src/util/allocator.h index 27b21c0..64bad23 100644 --- a/src/util/allocator.h +++ b/src/util/allocator.h @@ -5,10 +5,23 @@ #include <functional> #include "typedef.h" -template < typename T > +template <typename T> +struct LIST_ITERATOR { + T* ptr; + + LIST_ITERATOR( T* ptr ) : ptr( ptr ) {} + T& operator*() { return *ptr; } + T* operator->() { return ptr; } + LIST_ITERATOR& operator++() { ptr++; return *this; } + LIST_ITERATOR operator+=( U8 n ) { ptr += n; return *this; } + bool operator==( const LIST_ITERATOR& other ) { return ptr == other.ptr; } + bool operator!=( const LIST_ITERATOR& other ) { return ptr != other.ptr; } +}; + +template <typename T> using QSORT_FN = std::function< U8( T*, T* ) >; -template < typename T > +template <typename T> static U8 qsort_basic_sort( T* t1, T* t2 ) { return (*t1 > *t2); } @@ -63,6 +76,13 @@ struct LIST { size = 0; } + LIST( U32 _size, const T* data ) { + data = (T*)malloc( sizeof( T ) * _size ); + memcpy( data, data, _size * sizeof( T ) ); + size = _size; + capacity = _size; + } + LIST( const LIST<T>& other ) { if( !other.capacity || !other.size ) { capacity = 1; @@ -91,6 +111,7 @@ struct LIST { capacity = 1; size = 0; data = (T*)malloc( sizeof( T ) ); + memset( data, 0, sizeof( T ) ); return *this; } @@ -106,6 +127,10 @@ struct LIST { free( data ); } + T at( U32 index ) { + return data[index]; + } + void reserve( U32 count ) { if( capacity >= count ) return; @@ -320,4 +345,12 @@ struct LIST { ret.sort( fn ); return ret; } + + LIST_ITERATOR<T> begin() { + return LIST_ITERATOR<T>( data ); + } + + LIST_ITERATOR<T> end() { + return LIST_ITERATOR<T>( data + size ); + } }; |
