Arrays without code generation (#6)

Co-authored-by: Abdelrahman Said <said.abdelrahman@flawlessai.com>
Reviewed-on: #6
Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com>
Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
This commit is contained in:
2025-12-14 01:47:43 +00:00
committed by Abdelrahman Said
parent 331f7e5e4e
commit de9ce5791a
40 changed files with 581 additions and 4796 deletions

View File

@@ -61,13 +61,14 @@ u64 wapp_file_get_length(File *file) {
return output;
}
u64 wapp_file_read(GenericArray *dst, File *file, u64 item_count) {
wapp_debug_assert(dst != NULL && dst->items != NULL && file != NULL,
"`dst`, `dst->items` and `file` should not be NULL.");
u64 wapp_file_read(u8 *dst_byte_array, File *file, u64 item_count) {
wapp_debug_assert(dst_byte_array != NULL && file != NULL,
"`dst_byte_array` and `file` should not be NULL.");
u64 file_length = wapp_file_get_length(file);
u64 dst_byte_capacity = dst->item_size * dst->capacity;
u64 req_byte_count = item_count * dst->item_size;
u64 item_size = wapp_array_item_size(dst_byte_array);
u64 dst_byte_capacity = wapp_array_capacity(dst_byte_array) * item_size;
u64 req_byte_count = item_count * item_size;
u64 copy_byte_count = 0;
if (req_byte_count <= file_length && req_byte_count <= dst_byte_capacity) {
@@ -76,20 +77,24 @@ u64 wapp_file_read(GenericArray *dst, File *file, u64 item_count) {
copy_byte_count = file_length <= dst_byte_capacity ? file_length : dst_byte_capacity;
}
dst->count = fread(dst->items, sizeof(u8), copy_byte_count, file) / dst->item_size;
u64 count = fread(dst_byte_array, sizeof(u8), copy_byte_count, file);
if (ferror(file)) { return 0; }
return dst->count;
wapp_array_set_count(dst_byte_array, count / item_size);
return wapp_array_count(dst_byte_array);
}
u64 wapp_file_write(const GenericArray *src, File *file, u64 item_count) {
wapp_debug_assert(src != NULL && src->items != NULL && file != NULL,
"`src`, `src->items` and `file` should not be NULL.");
u64 wapp_file_write(const u8 *src_byte_array, File *file, u64 item_count) {
wapp_debug_assert(src_byte_array != NULL && file != NULL,
"`src_byte_array` and `file` should not be NULL.");
u64 src_byte_count = src->count * src->item_size;
u64 req_byte_count = item_count * src->item_size;
u64 item_size = wapp_array_item_size(src_byte_array);
u64 src_byte_count = wapp_array_count(src_byte_array) * item_size;
u64 req_byte_count = item_count * item_size;
u64 to_copy = req_byte_count <= src_byte_count ? req_byte_count : src_byte_count;
return fwrite(src->items, sizeof(u8), to_copy, file);
return fwrite(src_byte_array, sizeof(u8), to_copy, file);
}
i32 wapp_file_flush(File *file) {