Switch array fill to flags
This commit is contained in:
@@ -17,8 +17,8 @@ BEGIN_C_LINKAGE
|
||||
#define _calc_array_count(TYPE, ...) wapp_misc_utils_va_args_count(TYPE, __VA_ARGS__)
|
||||
#define _calc_array_capacity(TYPE, ...) wapp_misc_utils_u64_round_up_pow2(_calc_array_count(TYPE, __VA_ARGS__) * 2)
|
||||
|
||||
#define wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, FILL) \
|
||||
((TYPE *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(TYPE), FILL))
|
||||
#define wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, FLAGS) \
|
||||
((TYPE *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(TYPE), FLAGS))
|
||||
|
||||
typedef struct Str8 Str8;
|
||||
|
||||
@@ -44,6 +44,11 @@ typedef uptr *UptrArray;
|
||||
typedef iptr *IptrArray;
|
||||
typedef Str8 *Str8Array;
|
||||
|
||||
typedef enum {
|
||||
ARRAY_INIT_NONE = 0,
|
||||
ARRAY_INIT_FILLED = 1 << 1,
|
||||
} ArrayInitFlags;
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#define wapp_array(TYPE, ...) ([&]() { \
|
||||
u64 capacity = _calc_array_capacity(TYPE, __VA_ARGS__); \
|
||||
@@ -63,13 +68,13 @@ typedef Str8 *Str8Array;
|
||||
memcpy(buf, items, capacity * sizeof(TYPE)); \
|
||||
return (TYPE *)buf; \
|
||||
}())
|
||||
#define wapp_array_with_capacity(TYPE, CAPACITY, FILL) ([&]() { \
|
||||
#define wapp_array_with_capacity(TYPE, CAPACITY, FLAGS) ([&]() { \
|
||||
wapp_persist u8 array[ \
|
||||
sizeof(ArrayHeader) + CAPACITY * sizeof(TYPE) \
|
||||
] = {0}; \
|
||||
ArrayHeader *header = (ArrayHeader *)array; \
|
||||
header->magic = WAPP_ARRAY_MAGIC; \
|
||||
header->count = FILL ? CAPACITY : 0; \
|
||||
header->count = (FLAGS & ARRAY_INIT_FILLED) ? CAPACITY : 0; \
|
||||
header->capacity = CAPACITY; \
|
||||
header->item_size = sizeof(TYPE); \
|
||||
\
|
||||
@@ -100,12 +105,12 @@ typedef Str8 *Str8Array;
|
||||
.items = {__VA_ARGS__}, \
|
||||
}.items \
|
||||
))
|
||||
#define wapp_array_with_capacity(TYPE, CAPACITY, FILL) \
|
||||
#define wapp_array_with_capacity(TYPE, CAPACITY, FLAGS) \
|
||||
((TYPE *)( \
|
||||
(_stack_array(TYPE, CAPACITY)){ \
|
||||
.header = { \
|
||||
.magic = WAPP_ARRAY_MAGIC, \
|
||||
.count = FILL ? CAPACITY : 0, \
|
||||
.count = (FLAGS & ARRAY_INIT_FILLED) ? CAPACITY : 0, \
|
||||
.capacity = CAPACITY, \
|
||||
.item_size = sizeof(TYPE), \
|
||||
}, \
|
||||
@@ -191,7 +196,8 @@ GenericArray _array_copy_alloc(const Allocator *allocator, GenericArray dst, con
|
||||
void *_array_pop(GenericArray array, u64 item_size);
|
||||
void _array_clear(GenericArray array, u64 item_size);
|
||||
u64 _array_alloc_size(u64 capacity, u64 item_size);
|
||||
GenericArray _array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size, b8 fill);
|
||||
GenericArray _array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size,
|
||||
ArrayInitFlags flags);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
Reference in New Issue
Block a user