Add code generation for array
This commit is contained in:
21
codegen/array/snippets/extend_alloc
Normal file
21
codegen/array/snippets/extend_alloc
Normal file
@@ -0,0 +1,21 @@
|
||||
{ArrayType} *output = array;
|
||||
|
||||
if (!allocator || !array || !other) {{
|
||||
goto RETURN_{Tupper}_ARRAY_EXTEND_ALLOC;
|
||||
}}
|
||||
|
||||
u64 remaining_capacity = array->capacity - array->count;
|
||||
if (other->count >= remaining_capacity) {{
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2);
|
||||
output = wapp_{Tlower}_array_alloc_capacity(allocator, new_capacity);
|
||||
if (!output) {{
|
||||
output = array;
|
||||
goto RETURN_{Tupper}_ARRAY_EXTEND_ALLOC;
|
||||
}}
|
||||
wapp_{Tlower}_array_copy_capped(array, output);
|
||||
}}
|
||||
|
||||
wapp_{Tlower}_array_extend_capped(output, other);
|
||||
|
||||
RETURN_{Tupper}_ARRAY_EXTEND_ALLOC:
|
||||
return output;
|
Reference in New Issue
Block a user