Compare commits
3 Commits
3f9a908860
...
mem_contex
| Author | SHA1 | Date | |
|---|---|---|---|
| 6195b521f5 | |||
| be64571b0e | |||
| 645686ae22 |
@@ -10,8 +10,8 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct dstr String;
|
typedef struct dstr String;
|
||||||
|
|
||||||
String *wapp_dstr_with_capacity(u64 capacity, Allocator *allocator);
|
String *wapp_dstr_with_capacity(u64 capacity, const Allocator *allocator);
|
||||||
String *wapp_dstr_from_string(const char *str, 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_update(String **dst, const char *src);
|
||||||
void wapp_dstr_free(String **str);
|
void wapp_dstr_free(String **str);
|
||||||
void wapp_dstr_concat(String **dst, const char *src);
|
void wapp_dstr_concat(String **dst, const char *src);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ struct dstr {
|
|||||||
char buf[];
|
char buf[];
|
||||||
};
|
};
|
||||||
|
|
||||||
String *wapp_dstr_with_capacity(u64 capacity, Allocator *allocator) {
|
String *wapp_dstr_with_capacity(u64 capacity, const Allocator *allocator) {
|
||||||
Allocator alloc;
|
Allocator alloc;
|
||||||
if (allocator) {
|
if (allocator) {
|
||||||
alloc = *allocator;
|
alloc = *allocator;
|
||||||
@@ -38,7 +38,7 @@ String *wapp_dstr_with_capacity(u64 capacity, Allocator *allocator) {
|
|||||||
return out;
|
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) {
|
if (!str) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -182,9 +182,6 @@ i64 wapp_dstr_find(const String *str, const char *substr) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[substr_length + 1];
|
|
||||||
memset(buf, 0, substr_length + 1);
|
|
||||||
|
|
||||||
const char *s1;
|
const char *s1;
|
||||||
for (u64 i = 0; i < str->size; ++i) {
|
for (u64 i = 0; i < str->size; ++i) {
|
||||||
if (i + substr_length > str->size) {
|
if (i + substr_length > str->size) {
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
{ 0x57, 0x41, 0x41, 0x52, 0x4e, 0x48, 0x44, 0x52 }
|
{ 0x57, 0x41, 0x41, 0x52, 0x4e, 0x48, 0x44, 0x52 }
|
||||||
#define MAX_HDR_SEARCH_LENGTH 256
|
#define MAX_HDR_SEARCH_LENGTH 256
|
||||||
|
|
||||||
|
#define ARENA_MINIMUM_CAPACITY 1024
|
||||||
|
|
||||||
typedef struct arena_alloc_hdr ArenaAllocHDR;
|
typedef struct arena_alloc_hdr ArenaAllocHDR;
|
||||||
struct arena_alloc_hdr {
|
struct arena_alloc_hdr {
|
||||||
u8 magic[HDR_MAGIC_BYTE_COUNT];
|
u8 magic[HDR_MAGIC_BYTE_COUNT];
|
||||||
@@ -282,12 +284,15 @@ internal bool base_arena_init(BaseArena *arena, u64 capacity) {
|
|||||||
return false;
|
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)) {
|
if (!(arena->buf)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
arena->capacity = capacity;
|
arena->capacity = arena_capacity;
|
||||||
arena->offset = arena->buf;
|
arena->offset = arena->buf;
|
||||||
arena->prev = arena->next = NULL;
|
arena->prev = arena->next = NULL;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user