Update codegen
This commit is contained in:
@@ -21,14 +21,14 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
||||
Str8 separator = wapp_str8_buf(4);
|
||||
wapp_str8_push_back(&separator, PATH_SEP);
|
||||
|
||||
u64 required_capacity = parts->node_count * separator.size + parts->total_size;
|
||||
u64 required_capacity = parts->node_count * separator.size + wapp_str8_list_total_size(parts);
|
||||
if (dst->capacity < required_capacity) {
|
||||
return CPATH_JOIN_INSUFFICIENT_DST_CAPACITY;
|
||||
}
|
||||
|
||||
// Handle first node
|
||||
const Str8Node *first_node = wapp_str8_list_get(parts, 0);
|
||||
wapp_str8_copy_str8_capped(dst, first_node->string);
|
||||
wapp_str8_copy_str8_capped(dst, first_node->item);
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
@@ -37,13 +37,13 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
||||
bool running = true;
|
||||
while (running && node->next) {
|
||||
node = node->next;
|
||||
if (node->string->size == 0) {
|
||||
if (node->item->size == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dst->size > 0) {
|
||||
char dst_last = wapp_str8_get(dst, dst->size - 1);
|
||||
char node_start = wapp_str8_get(node->string, 0);
|
||||
char node_start = wapp_str8_get(node->item, 0);
|
||||
bool add_path_sep = dst_last != PATH_SEP && node_start != PATH_SEP;
|
||||
|
||||
if (add_path_sep) {
|
||||
@@ -51,7 +51,7 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
||||
}
|
||||
}
|
||||
|
||||
wapp_str8_concat_capped(dst, node->string);
|
||||
wapp_str8_concat_capped(dst, node->item);
|
||||
|
||||
++node_index;
|
||||
running = node_index < parts->node_count;
|
||||
@@ -108,7 +108,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
|
||||
}
|
||||
|
||||
u64 alignment = sizeof(void *) * 2;
|
||||
u64 alloc_size = parts->total_size + parts->node_count * separator.size;
|
||||
u64 alloc_size = wapp_str8_list_total_size(parts) + parts->node_count * separator.size;
|
||||
u64 modulo = alloc_size & (alignment - 1);
|
||||
alloc_size += alignment - modulo;
|
||||
|
||||
|
@@ -311,7 +311,7 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
|
||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->string = full;
|
||||
node->item = full;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
|
||||
before_str = wapp_str8_alloc_substr(allocator, str, start, start + end);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->string = before_str;
|
||||
node->item = before_str;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
|
||||
rest = wapp_str8_alloc_substr(allocator, str, start, str->size);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->string = rest;
|
||||
node->item = rest;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
|
||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->string = full;
|
||||
node->item = full;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
|
||||
after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->string = after_str;
|
||||
node->item = after_str;
|
||||
wapp_str8_list_push_front(output, node);
|
||||
}
|
||||
|
||||
@@ -399,7 +399,7 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
|
||||
rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->string = rest;
|
||||
node->item = rest;
|
||||
wapp_str8_list_push_front(output, node);
|
||||
}
|
||||
|
||||
@@ -412,7 +412,7 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u64 capacity = list->total_size + (delimiter->size * (list->node_count - 1));
|
||||
u64 capacity = wapp_str8_list_total_size(list) + (delimiter->size * (list->node_count - 1));
|
||||
Str8 *output = wapp_str8_alloc_buf(allocator, capacity * 2);
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
@@ -422,7 +422,7 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d
|
||||
bool running = true;
|
||||
while (running) {
|
||||
node = wapp_str8_list_get(list, node_index);
|
||||
wapp_str8_concat_capped(output, node->string);
|
||||
wapp_str8_concat_capped(output, node->item);
|
||||
if (node_index + 1 < list->node_count) {
|
||||
wapp_str8_concat_capped(output, delimiter);
|
||||
}
|
||||
@@ -435,5 +435,15 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d
|
||||
}
|
||||
|
||||
u64 wapp_str8_list_total_size(const Str8List *list) {
|
||||
if (!list) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 output = 0;
|
||||
for (u64 i = 0; i < list->node_count; ++i) {
|
||||
Str8Node *node = wapp_str8_list_get(list, i);
|
||||
output += node->item->size;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@
|
||||
internal Str8List str8_node_to_list(Str8Node *node);
|
||||
|
||||
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
|
||||
if (index >= list->node_count) {
|
||||
if (index >= list->node_count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
|
||||
}
|
||||
|
||||
void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
|
||||
}
|
||||
|
||||
void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
|
||||
}
|
||||
|
||||
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
|
||||
}
|
||||
|
||||
Str8Node *wapp_str8_list_pop_front(Str8List *list) {
|
||||
Str8Node *output = NULL;
|
||||
Str8Node *output = NULL;
|
||||
|
||||
if (!list || list->node_count == 0) {
|
||||
goto RETURN_STR8_LIST_POP_FRONT;
|
||||
@@ -126,7 +126,7 @@ RETURN_STR8_LIST_POP_FRONT:
|
||||
}
|
||||
|
||||
Str8Node *wapp_str8_list_pop_back(Str8List *list) {
|
||||
Str8Node *output = NULL;
|
||||
Str8Node *output = NULL;
|
||||
|
||||
if (!list || list->node_count == 0) {
|
||||
goto RETURN_STR8_LIST_POP_BACK;
|
||||
@@ -149,7 +149,7 @@ RETURN_STR8_LIST_POP_BACK:
|
||||
}
|
||||
|
||||
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) {
|
||||
Str8Node *output = NULL;
|
||||
Str8Node *output = NULL;
|
||||
if (!list) {
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ RETURN_STR8_LIST_REMOVE:
|
||||
}
|
||||
|
||||
void wapp_str8_list_empty(Str8List *list) {
|
||||
if (!list) {
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ void wapp_str8_list_empty(Str8List *list) {
|
||||
}
|
||||
|
||||
internal Str8List str8_node_to_list(Str8Node *node) {
|
||||
Str8List output = {.first = node, .last = node, .node_count = 1};
|
||||
Str8List output = {.first = node, .last = node, .node_count = 1};
|
||||
|
||||
while (output.first->prev != NULL) {
|
||||
output.first = output.first->prev;
|
||||
|
Reference in New Issue
Block a user