Add code generation for array
This commit is contained in:
20
codegen/array/snippets/append_alloc
Normal file
20
codegen/array/snippets/append_alloc
Normal file
@@ -0,0 +1,20 @@
|
||||
{ArrayType} *output = array;
|
||||
|
||||
if (!allocator || !array) {{
|
||||
goto RETURN_{Tupper}_ARRAY_APPEND_ALLOC;
|
||||
}}
|
||||
|
||||
if (array->count >= array->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_APPEND_ALLOC;
|
||||
}}
|
||||
wapp_{Tlower}_array_copy_capped(array, output);
|
||||
}}
|
||||
|
||||
wapp_{Tlower}_array_append_capped(output, item);
|
||||
|
||||
RETURN_{Tupper}_ARRAY_APPEND_ALLOC:
|
||||
return output;
|
Reference in New Issue
Block a user