3 Commits

Author SHA1 Message Date
6195b521f5 Set minimum capacity for arena 2024-04-21 23:59:00 +01:00
be64571b0e Pass allocator as const * 2024-03-31 17:29:23 +01:00
645686ae22 Remove unused variable 2024-03-31 17:05:04 +01:00
3 changed files with 11 additions and 9 deletions

View File

@@ -10,8 +10,8 @@ extern "C" {
typedef struct dstr String;
String *wapp_dstr_with_capacity(u64 capacity, Allocator *allocator);
String *wapp_dstr_from_string(const char *str, Allocator *allocator);
String *wapp_dstr_with_capacity(u64 capacity, const Allocator *allocator);
String *wapp_dstr_from_string(const char *str, const Allocator *allocator);
void wapp_dstr_update(String **dst, const char *src);
void wapp_dstr_free(String **str);
void wapp_dstr_concat(String **dst, const char *src);

View File

@@ -17,7 +17,7 @@ struct dstr {
char buf[];
};
String *wapp_dstr_with_capacity(u64 capacity, Allocator *allocator) {
String *wapp_dstr_with_capacity(u64 capacity, const Allocator *allocator) {
Allocator alloc;
if (allocator) {
alloc = *allocator;
@@ -38,7 +38,7 @@ String *wapp_dstr_with_capacity(u64 capacity, Allocator *allocator) {
return out;
}
String *wapp_dstr_from_string(const char *str, Allocator *allocator) {
String *wapp_dstr_from_string(const char *str, const Allocator *allocator) {
if (!str) {
return NULL;
}
@@ -182,9 +182,6 @@ i64 wapp_dstr_find(const String *str, const char *substr) {
return -1;
}
char buf[substr_length + 1];
memset(buf, 0, substr_length + 1);
const char *s1;
for (u64 i = 0; i < str->size; ++i) {
if (i + substr_length > str->size) {

View File

@@ -18,6 +18,8 @@
{ 0x57, 0x41, 0x41, 0x52, 0x4e, 0x48, 0x44, 0x52 }
#define MAX_HDR_SEARCH_LENGTH 256
#define ARENA_MINIMUM_CAPACITY 1024
typedef struct arena_alloc_hdr ArenaAllocHDR;
struct arena_alloc_hdr {
u8 magic[HDR_MAGIC_BYTE_COUNT];
@@ -282,12 +284,15 @@ internal bool base_arena_init(BaseArena *arena, u64 capacity) {
return false;
}
arena->buf = (u8 *)calloc(capacity, sizeof(u8));
u64 arena_capacity =
capacity >= ARENA_MINIMUM_CAPACITY ? capacity : ARENA_MINIMUM_CAPACITY;
arena->buf = (u8 *)calloc(arena_capacity, sizeof(u8));
if (!(arena->buf)) {
return false;
}
arena->capacity = capacity;
arena->capacity = arena_capacity;
arena->offset = arena->buf;
arena->prev = arena->next = NULL;