From 1856e297630d2cd243db52a3976f4cfea59d1636 Mon Sep 17 00:00:00 2001 From: Spencer Brower <6729162+sbrow@users.noreply.github.com> Date: Tue, 21 Jul 2026 15:48:00 -0400 Subject: [PATCH] perf: Fixed leaks. --- mustache/diagnostic_test.odin | 2 -- mustache/mustache.odin | 2 -- mustache/suggest.odin | 8 ++++---- mustache/suggest_test.odin | 1 + 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/mustache/diagnostic_test.odin b/mustache/diagnostic_test.odin index 1bc0e60..a4081fc 100644 --- a/mustache/diagnostic_test.odin +++ b/mustache/diagnostic_test.odin @@ -365,7 +365,6 @@ test_gutter_pipes_align_with_source_pipe :: proc(t: ^testing.T) { // For width=1: source line is "N | ...", so "|" at col 2. // Empty gutter is " |" (width+1 spaces + "|"), so "|" at col 2. lines := strings.split(out, "\n", context.temp_allocator) - defer delete(lines) pipe_col := -1 for line in lines { idx := strings.index(line, "|") @@ -387,7 +386,6 @@ test_arrow_points_at_pipe :: proc(t: ^testing.T) { // For width=1: arrow line is " --> ..." so ">" at col 3. // Pipe lines are " |" so "|" at col 2. lines := strings.split(out, "\n", context.temp_allocator) - defer delete(lines) pipe_col := -1 for line in lines { diff --git a/mustache/mustache.odin b/mustache/mustache.odin index 98da7a3..f939ccf 100644 --- a/mustache/mustache.odin +++ b/mustache/mustache.odin @@ -846,7 +846,6 @@ warn_missing_partial :: proc( ) { hint := "" available := collect_partial_names(partials) - defer delete(available) suggestion := suggest_correction(available, name) if suggestion != "" { hint = fmt.tprintf("did you mean '%s'?", suggestion) @@ -872,7 +871,6 @@ warn_unmatched_block_overrides :: proc( return } available := collect_block_names(parent) - defer delete(available) parent_path := parent.path if parent_path == "" { parent_path = "" diff --git a/mustache/suggest.odin b/mustache/suggest.odin index 1b91b69..257b112 100644 --- a/mustache/suggest.odin +++ b/mustache/suggest.odin @@ -6,7 +6,7 @@ import "core:strings" // collect_struct_keys enumerates the visible field names of a struct value, // including fields promoted via `using`-embedded structs. collect_struct_keys :: proc(val: any, allocator := context.temp_allocator) -> []string { - out: [dynamic]string + out := make([dynamic]string, 0, 0, allocator) collect_struct_keys_into(val, &out, allocator) return out[:] } @@ -111,7 +111,7 @@ validate_key_path :: proc( } if !found { - keys: [dynamic]string + keys := make([dynamic]string, 0, 4, allocator) for i := len(ctx) - 1; i >= 0; i -= 1 { collect_struct_keys_into(ctx[i], &keys, allocator) } @@ -178,7 +178,7 @@ collect_partial_names :: proc( partials: map[string]Template, allocator := context.temp_allocator, ) -> []string { - out: [dynamic]string + out := make([dynamic]string, 0, 0, allocator) for name in partials { append(&out, name) } @@ -191,7 +191,7 @@ collect_block_names :: proc( tmpl: Template, allocator := context.temp_allocator, ) -> []string { - out: [dynamic]string + out := make([dynamic]string, 0, 0, allocator) seen := make(map[string]bool, allocator) defer delete(seen) for &node in tmpl.nodes { diff --git a/mustache/suggest_test.odin b/mustache/suggest_test.odin index d42dd2f..3a168de 100644 --- a/mustache/suggest_test.odin +++ b/mustache/suggest_test.odin @@ -139,6 +139,7 @@ test_validate_map_path_silent :: proc(t: ^testing.T) { data := Params_Data { params = {"social" = "x"}, } + defer delete(data.params) ctx := make([dynamic]any, 0, 1, context.temp_allocator) append(&ctx, data)