summaryrefslogtreecommitdiff
path: root/src/locations.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/locations.zig')
-rw-r--r--src/locations.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/locations.zig b/src/locations.zig
index 40f22f85..d0904607 100644
--- a/src/locations.zig
+++ b/src/locations.zig
@@ -36,6 +36,30 @@ pub fn freeRows(gpa: std.mem.Allocator, rows: []Row) void {
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;
+ }
+ return out;
+}
+
/// A list of rows being built, given up: each row's own bytes, then the list.
pub fn freeRowList(gpa: std.mem.Allocator, rows: *std.ArrayList(Row)) void {
for (rows.items) |row| {