Rename array parameters
This commit is contained in:
@@ -70,35 +70,35 @@ void _array_append_capped(u8 *array, u8 *value, u64 item_size) {
|
||||
_array_set(array, index, value, item_size);
|
||||
}
|
||||
|
||||
void _array_extend_capped(u8 *array, const u8 *other, u64 item_size) {
|
||||
wapp_debug_assert(array != NULL && other != NULL, "`array` and `other` should not be NULL");
|
||||
void _array_extend_capped(u8 *dst_array, const u8 *src_array, u64 item_size) {
|
||||
wapp_debug_assert(dst_array != NULL && src_array != NULL, "`dst_array` and `src_array` should not be NULL");
|
||||
|
||||
ArrayHeader *dst_header = _array_header(array);
|
||||
ArrayHeader *src_header = _array_header(other);
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst_header->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src_header->magic, "`other` is not a valid wapp array");
|
||||
ArrayHeader *dst_header = _array_header(dst_array);
|
||||
ArrayHeader *src_header = _array_header(src_array);
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst_header->magic, "`dst_array` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src_header->magic, "`src_array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == dst_header->item_size && item_size == src_header->item_size, "Invalid item type provided");
|
||||
|
||||
u64 remaining_capacity = dst_header->capacity - dst_header->count;
|
||||
|
||||
u64 copy_count = src_header->count < remaining_capacity ? src_header->count : remaining_capacity;
|
||||
u8 *dst_ptr = array + dst_header->count * dst_header->item_size;
|
||||
memcpy((void *)dst_ptr, (const void *)other, copy_count * src_header->item_size);
|
||||
u8 *dst_ptr = dst_array + dst_header->count * dst_header->item_size;
|
||||
memcpy((void *)dst_ptr, (const void *)src_array, copy_count * src_header->item_size);
|
||||
dst_header->count += copy_count;
|
||||
}
|
||||
|
||||
void _array_copy_capped(u8 *array, const u8 *other, u64 item_size) {
|
||||
wapp_debug_assert(array != NULL && other != NULL, "`array` and `other` should not be NULL");
|
||||
void _array_copy_capped(u8 *dst_array, const u8 *src_array, u64 item_size) {
|
||||
wapp_debug_assert(dst_array != NULL && src_array != NULL, "`dst_array` and `src_array` should not be NULL");
|
||||
|
||||
ArrayHeader *dst_header = _array_header(array);
|
||||
ArrayHeader *src_header = _array_header(other);
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst_header->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src_header->magic, "`other` is not a valid wapp array");
|
||||
ArrayHeader *dst_header = _array_header(dst_array);
|
||||
ArrayHeader *src_header = _array_header(src_array);
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst_header->magic, "`dst_array` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src_header->magic, "`src_array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == dst_header->item_size && item_size == src_header->item_size, "Invalid item type provided");
|
||||
|
||||
_array_clear(array, item_size);
|
||||
_array_clear(dst_array, item_size);
|
||||
u64 copy_count = src_header->count < dst_header->capacity ? src_header->count : dst_header->capacity;
|
||||
memcpy((void *)array, (const void *)other, copy_count * src_header->item_size);
|
||||
memcpy((void *)dst_array, (const void *)src_array, copy_count * src_header->item_size);
|
||||
dst_header->count = copy_count;
|
||||
}
|
||||
|
||||
@@ -127,55 +127,55 @@ RETURN_ARRAY_APPEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
u8 *_array_extend_alloc(const Allocator *allocator, u8 *array, const u8 *other, u64 item_size) {
|
||||
wapp_debug_assert(allocator != NULL && array != NULL && other != NULL, "`allocator`, `array` and `other` should not be NULL");
|
||||
u8 *_array_extend_alloc(const Allocator *allocator, u8 *dst_array, const u8 *src_array, u64 item_size) {
|
||||
wapp_debug_assert(allocator != NULL && dst_array != NULL && src_array != NULL, "`allocator`, `dst_array` and `src_array` should not be NULL");
|
||||
|
||||
ArrayHeader *dst_header = _array_header(array);
|
||||
ArrayHeader *src_header = _array_header(other);
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst_header->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src_header->magic, "`other` is not a valid wapp array");
|
||||
ArrayHeader *dst_header = _array_header(dst_array);
|
||||
ArrayHeader *src_header = _array_header(src_array);
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst_header->magic, "`dst_array` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src_header->magic, "`src_array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == dst_header->item_size && item_size == src_header->item_size, "Invalid item type provided");
|
||||
|
||||
u8 *output = array;
|
||||
u8 *output = dst_array;
|
||||
|
||||
u64 remaining_capacity = dst_header->capacity - dst_header->count;
|
||||
if (src_header->count >= remaining_capacity) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst_header->capacity * 2);
|
||||
output = (u8 *)_array_alloc_capacity(allocator, new_capacity, dst_header->item_size);
|
||||
if (!output) {
|
||||
output = array;
|
||||
output = dst_array;
|
||||
goto RETURN_ARRAY_EXTEND_ALLOC;
|
||||
}
|
||||
_array_copy_capped(output, array, item_size);
|
||||
_array_copy_capped(output, dst_array, item_size);
|
||||
}
|
||||
|
||||
_array_extend_capped(output, other, item_size);
|
||||
_array_extend_capped(output, src_array, item_size);
|
||||
|
||||
RETURN_ARRAY_EXTEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
u8 *_array_copy_alloc(const Allocator *allocator, u8 *array, const u8 *other, u64 item_size) {
|
||||
wapp_debug_assert(allocator != NULL && array != NULL && other != NULL, "`allocator`, `array` and `other` should not be NULL");
|
||||
u8 *_array_copy_alloc(const Allocator *allocator, u8 *dst_array, const u8 *src_array, u64 item_size) {
|
||||
wapp_debug_assert(allocator != NULL && dst_array != NULL && src_array != NULL, "`allocator`, `dst_array` and `src_array` should not be NULL");
|
||||
|
||||
ArrayHeader *dst_header = _array_header(array);
|
||||
ArrayHeader *src_header = _array_header(other);
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst_header->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src_header->magic, "`other` is not a valid wapp array");
|
||||
ArrayHeader *dst_header = _array_header(dst_array);
|
||||
ArrayHeader *src_header = _array_header(src_array);
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst_header->magic, "`dst_array` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src_header->magic, "`src_array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == dst_header->item_size && item_size == src_header->item_size, "Invalid item type provided");
|
||||
|
||||
u8 *output = array;
|
||||
u8 *output = dst_array;
|
||||
|
||||
if (src_header->count >= dst_header->capacity) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst_header->capacity * 2);
|
||||
output = (u8 *)_array_alloc_capacity(allocator, new_capacity, src_header->item_size);
|
||||
if (!output) {
|
||||
output = array;
|
||||
output = dst_array;
|
||||
goto RETURN_ARRAY_COPY_ALLOC;
|
||||
}
|
||||
}
|
||||
|
||||
_array_copy_capped(output, other, item_size);
|
||||
_array_copy_capped(output, src_array, item_size);
|
||||
|
||||
RETURN_ARRAY_COPY_ALLOC:
|
||||
return output;
|
||||
|
||||
@@ -120,11 +120,11 @@ u64 _array_item_size(u8 *array, u64 item_size);
|
||||
u8 *_array_get(u8 *array, u64 index, u64 item_size);
|
||||
void _array_set(u8 *array, u64 index, u8 *value, u64 item_size);
|
||||
void _array_append_capped(u8 *array, u8 *value, u64 item_size);
|
||||
void _array_extend_capped(u8 *array, const u8 *other, u64 item_size);
|
||||
void _array_copy_capped(u8 *array, const u8 *other, u64 item_size);
|
||||
void _array_extend_capped(u8 *dst_array, const u8 *src_array, u64 item_size);
|
||||
void _array_copy_capped(u8 *dst_array, const u8 *src_array, u64 item_size);
|
||||
u8 *_array_append_alloc(const Allocator *allocator, u8 *array, u8 *value, u64 item_size);
|
||||
u8 *_array_extend_alloc(const Allocator *allocator, u8 *array, const u8 *other, u64 item_size);
|
||||
u8 *_array_copy_alloc(const Allocator *allocator, u8 *array, const u8 *other, u64 item_size);
|
||||
u8 *_array_extend_alloc(const Allocator *allocator, u8 *dst_array, const u8 *src_array, u64 item_size);
|
||||
u8 *_array_copy_alloc(const Allocator *allocator, u8 *dst_array, const u8 *src_array, u64 item_size);
|
||||
u8 *_array_pop(u8 *array, u64 item_size);
|
||||
void _array_clear(u8 *array, u64 item_size);
|
||||
u8 *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size);
|
||||
|
||||
Reference in New Issue
Block a user