diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Places.zig | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Places.zig b/src/Places.zig index 3dca3adf..818ca1d7 100644 --- a/src/Places.zig +++ b/src/Places.zig @@ -264,6 +264,14 @@ fn freshHay(set: *Places, gpa: std.mem.Allocator, f: *File.State) bool { if (set.hay.len > 0) gpa.rawFree(set.hay, .of(u8), @returnAddress()); set.hay = &.{}; set.hay = memory.unfilled(gpa, f.content.len) catch return false; + // What is not lowered yet is in the digest and a dump as well: zeros, + // the same in every process, not whatever its heap held (a replica's + // diverged). A pass over the text, as the edit that made it was. + // ponytail: 0.4 ms for 10 MB, 10 ms for 100 MB in one frame (ReleaseFast, + // page faults and all; lowering it is four times that, over frames). A + // digest and a dump of the lowered pieces alone if a huge text's first + // search ever shows. + @memset(set.hay, 0); set.low.resize(gpa, (f.content.len + chunk_bytes - 1) / chunk_bytes, false) catch return false; set.low.unsetAll(); set.hay_revision = f.revision; @@ -880,3 +888,27 @@ test "zz stress analysis cost" { std.testing.allocator.free(a.colors); std.debug.print("decls {d} us ({d}), analysis with colours {d} us\n", .{ (t1 - t0) / 1000, d.len, (t2 - t1) / 1000 }); } + +test "a lowered copy's pieces not searched yet are the same in every process: a digest and a dump take them" { + // Two sessions searching one text, each heap handing out other bytes in + // what is not written yet (rollback.Epoch.fill): their places agree. + const rollback = @import("rollback.zig"); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(std.testing.allocator); + for (0..2000) |i| try text.print(std.testing.allocator, "line {d} of a text in four pieces\n", .{i}); + var digests: [2]u64 = undefined; + for (&digests, [_]u8{ 0x11, 0x5a }) |*d, b| { + var e: rollback.Epoch = .{ .child = std.testing.allocator }; + defer e.deinit(); + rollback.Epoch.fill = b; + defer rollback.Epoch.fill = null; + const p = try Pardes.init(e.allocator(), .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + const pane = try p.setTestFile(text.items); + // The view's piece found now, the rest a frame at a time after. + pane.places.search(p, pane, .typed, 0, "piece", false, null, false); + try std.testing.expect(!pane.places.complete() and pane.places.fold); + d.* = pardes.walk.digest(Places, &pane.places); + } + try std.testing.expectEqual(digests[0], digests[1]); +} |
