From 398270fb7e121cbaab9e264a39bc83b5d32c40c7 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:07:25 -0300 Subject: locations: one appendRow copies a row's path and colours onto a list being built, for appendMetadata, hunks' Out.row and Query's writeRow, which each copied, appended and freed on failure by hand Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Query.zig | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/Query.zig') diff --git a/src/Query.zig b/src/Query.zig index 5fdfff2a..87c9d3bd 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -676,27 +676,20 @@ fn noteRows(p: *Pardes, id: usize, note: []const u8) void { setRows(p, rp, &out, &rows); } -/// One row: its text and its metadata, the path copied. +/// One row: its text and its metadata, the path and colours copied. fn writeRow(p: *Pardes, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), text: []const u8, meta: locations.Row) !void { try out.appendSlice(p.gpa, text); try out.append(p.gpa, '\n'); - var m = meta; - m.path = try p.gpa.dupe(u8, meta.path); - errdefer p.gpa.free(m.path); // Coloured whole (zeros where nothing coloured it): the pane's syntax // pass then parses no fragment of it, per refill. const code = text[@min(meta.code_start, text.len)..]; - m.colors = if (meta.colors.len >= code.len) try p.gpa.dupe(u8, meta.colors[0..code.len]) else blk: { - const c = try p.gpa.alloc(u8, code.len); - @memset(c, 0); - @memcpy(c[0..meta.colors.len], meta.colors); - break :blk c; - }; - rows.append(p.gpa, m) catch |err| { - p.gpa.free(m.path); - p.gpa.free(m.colors); - return err; - }; + var m = meta; + if (meta.colors.len >= code.len) m.colors = meta.colors[0..code.len] else { + m.colors = try p.scratch.allocator().alloc(u8, code.len); + @memset(m.colors, 0); + @memcpy(m.colors[0..meta.colors.len], meta.colors); + } + try locations.appendRow(p.gpa, rows, m); } /// The rows made into the pane: line 1 as it is (the user's), then `out`, -- cgit v1.3