Simplify arena_alloc implementation

This commit is contained in:
seajee
2025-07-24 15:55:26 +02:00
parent ff948662e5
commit 2c636c524d

10
arena.h
View File

@@ -84,13 +84,8 @@ void *arena_alloc(Arena *a, size_t bytes)
a->tail = a->tail->next;
}
// If found allocate on that region
if (bytes <= a->tail->capacity - a->tail->count) {
a->tail->count += bytes;
return a->tail->data + a->tail->count;
}
// If not create a new region
// If not found create a new region
if (bytes > a->tail->capacity - a->tail->count) {
size_t size = (bytes > region_capacity ? bytes : region_capacity);
a->tail->next = (Arena_Region*)ARENA_REALLOC(NULL, sizeof(*a->tail) + size);
ARENA_ASSERT(a->head != NULL);
@@ -102,6 +97,7 @@ void *arena_alloc(Arena *a, size_t bytes)
a->tail->capacity = size;
return a->tail->data;
}
}
a->tail->count += bytes;
return a->tail->data + a->tail->count;