diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:07:25 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-04 23:07:26 -0300 |
| commit | 398270fb7e121cbaab9e264a39bc83b5d32c40c7 (patch) | |
| tree | 3b1be9a8d97874ede9e62ecb4d0ac42ff3aa1329 /src/locations.zig | |
| parent | cdbb06a5de858a721bdbfa127ea839f791b0dc24 (diff) | |
| download | pardes-398270fb7e121cbaab9e264a39bc83b5d32c40c7.tar.gz pardes-398270fb7e121cbaab9e264a39bc83b5d32c40c7.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/locations.zig')
| -rw-r--r-- | src/locations.zig | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/locations.zig b/src/locations.zig index b14b3a2c..889a45a0 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -82,6 +82,17 @@ pub fn freeRowList(gpa: std.mem.Allocator, rows: *std.ArrayList(Row)) void { rows.deinit(gpa); } +/// `row` onto a list being built, with copies of its own of the path and +/// the colours it borrows. +pub fn appendRow(gpa: std.mem.Allocator, rows: *std.ArrayList(Row), row: Row) !void { + var owned = row; + owned.path = try gpa.dupe(u8, row.path); + errdefer gpa.free(owned.path); + owned.colors = try gpa.dupe(u8, row.colors); + errdefer gpa.free(owned.colors); + try rows.append(gpa, owned); +} + pub fn equalRows(a: []const Row, b: []const Row) bool { if (a.len != b.len) return false; for (a, b) |left, right| { @@ -601,11 +612,7 @@ fn writeCode(writer: *std.Io.Writer, rows: []const Pending, index: usize) !void } fn appendMetadata(gpa: std.mem.Allocator, rows: *std.ArrayList(Row), pending: Pending, kind: @FieldType(Row, "kind"), location_end: usize, code_start: usize, source: bool) !void { - const path = try gpa.dupe(u8, pending.path); - errdefer gpa.free(path); - const colors = try gpa.dupe(u8, if (source) pending.colors else &.{}); - errdefer gpa.free(colors); - try rows.append(gpa, .{ .kind = kind, .declaration = pending.declaration, .mark_occurrence = pending.mark_occurrence, .source_column = pending.source_column, .path = path, .at = pending.at, .location_end = location_end, .code_start = code_start, .colors = colors }); + try appendRow(gpa, rows, .{ .kind = kind, .declaration = pending.declaration, .mark_occurrence = pending.mark_occurrence, .source_column = pending.source_column, .path = @constCast(pending.path), .at = pending.at, .location_end = location_end, .code_start = code_start, .colors = @constCast(if (source) pending.colors else &.{}) }); } const alignment_entries = 8; |
