Update primitives
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "./array.h"
|
||||
#include "../../common/assert/assert.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../mem_allocator/mem_allocator.h"
|
||||
#include "../../common/misc/misc_utils.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
|
@@ -5,7 +5,6 @@
|
||||
#ifndef ARRAY_H
|
||||
#define ARRAY_H
|
||||
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../mem_allocator/mem_allocator.h"
|
||||
#include "../../common/misc/misc_utils.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
|
@@ -5,10 +5,8 @@
|
||||
#include "./dbl_list.h"
|
||||
#include "../../common/assert/assert.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
|
||||
internal Str8List str8_node_to_list(Str8Node *node);
|
||||
internal VoidPList void_ptr_node_to_list(VoidPNode *node);
|
||||
|
@@ -5,7 +5,6 @@
|
||||
#ifndef DBL_LIST_H
|
||||
#define DBL_LIST_H
|
||||
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
|
||||
|
@@ -163,7 +163,7 @@ Str8 *wapp_str8_alloc_concat(const Allocator *allocator, Str8 *dst, Str8RO *src)
|
||||
u64 remaining = dst->capacity - dst->size;
|
||||
if (src->size <= remaining) {
|
||||
output = dst;
|
||||
goto COPY_STRING_STR8_CONCAT;
|
||||
goto SOURCE_STRING_STR8_CONCAT;
|
||||
}
|
||||
|
||||
u64 capacity = dst->capacity + src->size;
|
||||
@@ -175,13 +175,60 @@ Str8 *wapp_str8_alloc_concat(const Allocator *allocator, Str8 *dst, Str8RO *src)
|
||||
|
||||
wapp_str8_concat_capped(output, dst);
|
||||
|
||||
COPY_STRING_STR8_CONCAT:
|
||||
SOURCE_STRING_STR8_CONCAT:
|
||||
wapp_str8_concat_capped(output, src);
|
||||
|
||||
RETURN_STR8_CONCAT:
|
||||
return output;
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_alloc_copy_cstr(const Allocator *allocator, Str8 *dst, const char *src) {
|
||||
wapp_debug_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
|
||||
Str8 *output = NULL;
|
||||
u64 size = strlen(src);
|
||||
if (size <= dst->capacity) {
|
||||
output = dst;
|
||||
goto SOURCE_CSTRING_STR8_COPY;
|
||||
}
|
||||
|
||||
u64 capacity = dst->capacity + size;
|
||||
|
||||
output = wapp_str8_alloc_buf(allocator, capacity);
|
||||
if (!output) {
|
||||
goto RETURN_CSTRING_STR8_COPY;
|
||||
}
|
||||
|
||||
SOURCE_CSTRING_STR8_COPY:
|
||||
wapp_str8_copy_cstr_capped(output, src);
|
||||
|
||||
RETURN_CSTRING_STR8_COPY:
|
||||
return output;
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_alloc_copy_str8(const Allocator *allocator, Str8 *dst, Str8RO *src) {
|
||||
wapp_debug_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
|
||||
Str8 *output = NULL;
|
||||
if (src->size <= dst->capacity) {
|
||||
output = dst;
|
||||
goto SOURCE_STRING_STR8_COPY;
|
||||
}
|
||||
|
||||
u64 capacity = dst->capacity + src->size;
|
||||
|
||||
output = wapp_str8_alloc_buf(allocator, capacity);
|
||||
if (!output) {
|
||||
goto RETURN_STRING_STR8_COPY;
|
||||
}
|
||||
|
||||
SOURCE_STRING_STR8_COPY:
|
||||
wapp_str8_copy_str8_capped(output, src);
|
||||
|
||||
RETURN_STRING_STR8_COPY:
|
||||
return output;
|
||||
}
|
||||
|
||||
void wapp_str8_concat_capped(Str8 *dst, Str8RO *src) {
|
||||
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
|
||||
|
@@ -79,6 +79,8 @@ Str8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str);
|
||||
Str8 *wapp_str8_alloc_str8(const Allocator *allocator, Str8RO *str);
|
||||
Str8 *wapp_str8_alloc_substr(const Allocator *allocator, Str8RO *str, u64 start, u64 end);
|
||||
Str8 *wapp_str8_alloc_concat(const Allocator *allocator, Str8 *dst, Str8RO *src);
|
||||
Str8 *wapp_str8_alloc_copy_cstr(const Allocator *allocator, Str8 *dst, const char *src);
|
||||
Str8 *wapp_str8_alloc_copy_str8(const Allocator *allocator, Str8 *dst, Str8RO *src);
|
||||
// Only needed for allocators like malloc where each allocation has to be freed on its own.
|
||||
// No need to use it for allocators like Arena.
|
||||
void wapp_str8_dealloc_buf(const Allocator *allocator, Str8 **str);
|
||||
|
Reference in New Issue
Block a user