Only call get_args() if args is actually used by using an indirect value

This commit is contained in:
gingerBill
2025-12-16 15:09:21 +00:00
parent 548e4f3373
commit a0bcc73663

View File

@@ -15,6 +15,9 @@ Arguments to the current process.
*/
args := get_args()
@(private="file")
internal_args_to_free: []string
@(private="file")
get_args :: proc "contextless" () -> []string {
context = runtime.default_context()
@@ -22,13 +25,16 @@ get_args :: proc "contextless" () -> []string {
for rt_arg, i in runtime.args__ {
result[i] = string(rt_arg)
}
internal_args_to_free = result
return result
}
@(fini, private="file")
delete_args :: proc "contextless" () {
context = runtime.default_context()
delete(args, heap_allocator())
if internal_args_to_free != nil {
context = runtime.default_context()
delete(internal_args_to_free, heap_allocator())
}
}
/*