diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-31 06:28:48 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-31 06:28:48 -0300 |
| commit | a479792a1ab2b593642d7f648194bfa23ce01dba (patch) | |
| tree | 96ddee7d879a9084daa07db43b0b7910b072a785 /src/locations.zig | |
| parent | e179cc44fe5060c76a5b00c41e53f11209f5acd9 (diff) | |
| parent | 4c761893e5b3fdae422622cfa02104ab36633045 (diff) | |
| download | pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.tar.gz pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.zip | |
Merge the upstream daemon and replicated client/server refactor
Diffstat (limited to 'src/locations.zig')
| -rw-r--r-- | src/locations.zig | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/src/locations.zig b/src/locations.zig index cdb228a6..b14b3a2c 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const freeRaw = @import("memory.zig").freeRaw; const pardes = @import("pardes.zig"); const look = @import("look.zig"); const syntax = @import("syntax.zig"); @@ -23,14 +24,53 @@ pub const Row = struct { location_end: usize, code_start: usize, colors: []u8 = &.{}, + + /// The replay digest's (src/walk.zig): all of it but its colours. They + /// are painted from what this process has painted (the owner's + /// highlights a frame made, the locations cache: both derived), so a + /// client joined from a dump, or one that drew another view, colours a + /// row its session left plain. They are how a row looks, not where it + /// points; a dump keeps them. + pub fn digest(r: *const Row, h: *pardes.walk.Hasher) void { + inline for (@typeInfo(Row).@"struct".field_names) |name| { + if (comptime std.mem.eql(u8, name, "colors")) continue; + pardes.walk.hash(@FieldType(Row, name), &@field(r, name), h); + } + } }; +/// Raw (no safe build's overwrite): a replica's rollback copy pins a row +/// blob and what its rows own (src/rollback.zig `pinnedDeep`). pub fn freeRows(gpa: std.mem.Allocator, rows: []Row) void { for (rows) |row| { - gpa.free(row.path); - gpa.free(row.colors); + freeRaw(gpa, row.path); + freeRaw(gpa, row.colors); + } + freeRaw(gpa, rows); +} + +/// A copy of `rows` and all they own, gpa's: rows are a blob (File.State +/// `location_rows`), made again rather than written. +pub fn cloneRows(gpa: std.mem.Allocator, rows: []const Row) ![]Row { + const out = try gpa.alloc(Row, rows.len); + var made: usize = 0; + errdefer { + for (out[0..made]) |r| { + gpa.free(r.path); + gpa.free(r.colors); + } + gpa.free(out); + } + for (rows, out) |r, *o| { + o.* = r; + o.path = try gpa.dupe(u8, r.path); + o.colors = gpa.dupe(u8, r.colors) catch |err| { + gpa.free(o.path); + return err; + }; + made += 1; } - gpa.free(rows); + return out; } /// A list of rows being built, given up: each row's own bytes, then the list. |
