summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Places.zig57
-rw-r--r--src/Query.zig11
-rw-r--r--src/Tables.zig8
3 files changed, 23 insertions, 53 deletions
diff --git a/src/Places.zig b/src/Places.zig
index d5a4bb4d..e6858537 100644
--- a/src/Places.zig
+++ b/src/Places.zig
@@ -60,13 +60,6 @@ const chunk_bytes = 16 << 10;
/// A rail's ticks are placed to 1/`tick_scale` of the file.
pub const tick_scale = @import("surface.zig").rail_tick_scale;
-pub fn nowNs() u64 {
- if (comptime !pardes.hosted) return 0;
- var ts: std.c.timespec = undefined;
- if (std.c.clock_gettime(.MONOTONIC, &ts) != 0) return 0;
- return @as(u64, @intCast(ts.sec)) *| std.time.ns_per_s +| @as(u64, @intCast(ts.nsec));
-}
-
/// What the replay digest leaves out (src/walk.zig): the rail's ticks,
/// made again from the places when they are drawn.
pub const replica = .{ .derived = .{ "ticks", "ticks_gen", "re" } };
@@ -101,18 +94,13 @@ hi: usize = 0,
head_to: usize = 0,
nhead: usize = 0,
/// Where the last budget ran out: a line too slow for a whole frame's
-/// budget, run out at twice, is passed over and counted.
+/// budget, run out at twice, is passed over.
stuck_at: ?usize = null,
-skipped: u32 = 0,
-capped: bool = false,
current: ?usize = null,
/// The first place at or after this offset becomes current once the
/// search has got there; with `seek_moves` it takes the selection and view.
seek: ?usize = null,
seek_moves: bool = false,
-/// The last step went round the end of the text (or its start). Said by
-/// nothing but the count wrapping in the query pane's tag.
-wrapped: bool = false,
/// Moves with every change to the places or the current one (the ticks'
/// cue and the query pane's); `hits_gen` only with the places.
gen: u32 = 0,
@@ -148,7 +136,6 @@ pub fn clear(set: *Places, gpa: std.mem.Allocator) void {
set.from = 0;
set.current = null;
set.seek = null;
- set.wrapped = false;
set.gen +%= 1;
set.hits_gen +%= 1;
}
@@ -402,8 +389,6 @@ fn restart(set: *Places, p: *Pardes, f: *File.State) void {
set.head_to = 0;
set.nhead = 0;
set.stuck_at = null;
- set.skipped = 0;
- set.capped = false;
set.gen +%= 1;
set.hits_gen +%= 1;
if (set.re == null) {
@@ -420,7 +405,7 @@ fn restart(set: *Places, p: *Pardes, f: *File.State) void {
/// been searched, make it current. Run after every step (with no budget:
/// the view only) and every tick (a frame's).
pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) void {
- const started_ns = nowNs();
+ const started_ns = pardes.FrameStats.nowNs();
if (!set.started) return;
set.derive(p.gpa);
const f = if (pane.file) |*file| file else return set.clear(p.gpa);
@@ -448,7 +433,7 @@ pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) voi
}
if (set.fold and (set.hay_revision != f.revision or set.hay.len != f.content.len))
if (!set.freshHay(gpa, f)) return set.clear(gpa);
- if (set.re == null) return set.settleSeek(p, pane);
+ if (set.re == null) return set.settleSeek(pane);
const re = &set.re.?;
const hay: []const u8 = if (set.fold) set.hay else f.content;
for (re.branches) |*b| b.re.steps = @max(1, steps / re.branches.len);
@@ -477,7 +462,6 @@ pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) voi
head.clearRetainingCapacity();
while (at < to) {
if (set.hits.items.len + head.items.len >= max_hits) {
- set.capped = true;
at = to;
break;
}
@@ -501,7 +485,6 @@ pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) voi
// line is past searching and is passed over.
if (set.stuck_at == at) {
at = if (std.mem.indexOfScalarPos(u8, hay, at, '\n')) |nl| @min(to, nl + 1) else to;
- set.skipped += 1;
set.stuck_at = null;
} else set.stuck_at = at;
}
@@ -523,12 +506,12 @@ pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) voi
set.gen +%= 1;
set.hits_gen +%= 1;
}
- set.settleSeek(p, pane);
+ set.settleSeek(pane);
}
/// The place at or after `seek` becomes current, once all the text
/// between them has been searched (never a false "next" across a gap).
-fn settleSeek(set: *Places, p: *Pardes, pane: *Pane) void {
+fn settleSeek(set: *Places, pane: *Pane) void {
const seek = set.seek orelse return;
const hits = set.hits.items;
const i = firstFrom(hits, seek);
@@ -536,10 +519,8 @@ fn settleSeek(set: *Places, p: *Pardes, pane: *Pane) void {
const searched = if (set.head_to >= set.lo) between_to <= set.hi else between_to <= set.head_to or (seek >= set.lo and between_to <= set.hi);
if (i < hits.len and searched) {
set.current = i;
- set.wrapped = false;
} else if (set.complete()) {
set.current = if (hits.len > 0) 0 else null;
- set.wrapped = hits.len > 0 and seek > 0;
} else return;
set.seek = null;
set.gen +%= 1;
@@ -547,7 +528,7 @@ fn settleSeek(set: *Places, p: *Pardes, pane: *Pane) void {
if (set.current) |c| return set.goTo(pane, c, false);
// Nothing matches: the body as it was before the query, as helix
// leaves it.
- set.restore(p, pane);
+ set.restore(pane);
}
/// The places have more to do on a frame of their own: places still to
@@ -601,7 +582,6 @@ pub fn step(set: *Places, p: *Pardes, pane: *Pane, forward: bool, count: u32, ad
const hits = set.hits.items;
if (hits.len == 0) return;
const t = &pane.body;
- var wrapped = false;
for (0..count) |_| {
var ranges: [Text.max_selections]modal.Selection = undefined;
const got = t.ranges(f.content, 0, &ranges);
@@ -609,22 +589,15 @@ pub fn step(set: *Places, p: *Pardes, pane: *Pane, forward: bool, count: u32, ad
var i: usize = 0;
if (forward) {
i = firstFrom(hits, @max(old.anchor, old.head));
- if (i == hits.len) {
- i = 0;
- wrapped = true;
- }
+ if (i == hits.len) i = 0;
} else {
const from = @min(old.anchor, old.head);
i = firstFrom(hits, from);
while (i > 0 and hits[i - 1].end > from) i -= 1;
- if (i == 0) {
- i = hits.len - 1;
- wrapped = true;
- } else i -= 1;
+ i = if (i == 0) hits.len - 1 else i - 1;
}
set.goTo(pane, i, add);
}
- set.wrapped = wrapped;
}
/// Whether n and N in this pane are these places' to step: a list's or a
@@ -655,8 +628,7 @@ pub fn remember(set: *Places, p: *Pardes, pane: *Pane) void {
}
/// The body as `remember` kept it: its selections and its view.
-pub fn restore(set: *Places, p: *Pardes, pane: *Pane) void {
- _ = p;
+pub fn restore(set: *Places, pane: *Pane) void {
const f = if (pane.file) |*file| file else return;
if (set.snap.len == 0) return;
for (set.snap) |*r| {
@@ -821,7 +793,6 @@ test "places: * finds them all, n and N step them round the end silently, an edi
const logged = p.messages.len;
typeKeys(p, "n");
try std.testing.expectEqual(@as(?usize, 0), set.current);
- try std.testing.expect(set.wrapped);
// round the end without a word anywhere
try std.testing.expectEqual(logged, p.messages.len);
typeKeys(p, "N");
@@ -852,9 +823,9 @@ test "places: a big file costs a keystroke its view, the ticks find the rest, an
const set = &pane.places;
// The line index is the file's, made once whatever asks for it first.
_ = try File.lineIndex(p.gpa, &pane.file.?);
- const t0 = nowNs();
+ const t0 = pardes.FrameStats.nowNs();
set.search(p, pane, .typed, 0, "needle 3", false, 0, true);
- const first_ns = nowNs() - t0;
+ const first_ns = pardes.FrameStats.nowNs() - t0;
try std.testing.expect(set.hits.items.len > 0);
var ticks: usize = 0;
while (set.busy(pane) and ticks < 10_000) : (ticks += 1) set.settle(p, pane, true);
@@ -868,11 +839,11 @@ test "places: a big file costs a keystroke its view, the ticks find the rest, an
@memcpy(new[0..at], f.content[0..at]);
new[at] = 'x';
@memcpy(new[at + 1 ..], f.content[at..]);
- const t1 = nowNs();
+ const t1 = pardes.FrameStats.nowNs();
File.setContentSpan(p, f, new, null);
- const t2 = nowNs();
+ const t2 = pardes.FrameStats.nowNs();
set.settle(p, pane, false);
- const edit_ns = nowNs() - t2;
+ const edit_ns = pardes.FrameStats.nowNs() - t2;
const text_ns = t2 - t1;
try std.testing.expect(set.complete() and set.shows(pane));
try std.testing.expectEqual(all, set.hits.items.len);
diff --git a/src/Query.zig b/src/Query.zig
index 87c9d3bd..afda600c 100644
--- a/src/Query.zig
+++ b/src/Query.zig
@@ -451,7 +451,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void {
if (changed) {
if (a.pat.len == 0) {
if (set.from == rp.serial) set.clear(p.gpa);
- set.restore(p, owner);
+ set.restore(owner);
} else set.search(p, owner, .typed, rp.serial, a.pat, false, set.origin(owner), p.active == id);
}
// The owner edited: its places shifted at once; the rows follow
@@ -1454,7 +1454,7 @@ fn clearPlaces(p: *Pardes, serial: u32, owner_id: ?usize) void {
for (p.panes, 0..) |slot, i| {
const tp = slot orelse continue;
if (tp.places.from != serial) continue;
- if (owner_id != null and owner_id.? == i) tp.places.restore(p, tp);
+ if (owner_id != null and owner_id.? == i) tp.places.restore(tp);
tp.places.clear(p.gpa);
}
}
@@ -1895,7 +1895,7 @@ pub fn cancel(p: *Pardes, id: usize) void {
const owner_id = p.paneBySerial(q.owner);
for (p.panes) |slot| if (slot) |tp| {
if (tp.places.from != rp.serial and tp.serial != q.owner) continue;
- tp.places.restore(p, tp);
+ tp.places.restore(tp);
tp.places.forget(p.gpa);
if (tp.places.from == rp.serial) tp.places.clear(p.gpa);
};
@@ -2279,7 +2279,6 @@ test "a / query: Enter lands and freezes, the register filled, n and N step sile
try std.testing.expectEqual(@as(?usize, 3), pane.places.current);
typeKeys(p, "n");
try std.testing.expectEqual(@as(?usize, 0), pane.places.current);
- try std.testing.expect(pane.places.wrapped);
try std.testing.expectEqual(logged, p.messages.len);
typeKeys(p, "N");
try std.testing.expectEqual(@as(?usize, 3), pane.places.current);
@@ -2444,11 +2443,11 @@ test "zz query timings on the 1.2 MB stress file (QUERY_TIMES=<path>)" {
_ = try p.render(frame.allocator());
const Clock = struct {
fn step(pp: *Pardes, fr: *std.heap.ArenaAllocator, ev: pardes.Event) !u64 {
- const t0 = Places.nowNs();
+ const t0 = pardes.FrameStats.nowNs();
pp.update(ev);
_ = fr.reset(.retain_capacity);
_ = try pp.render(fr.allocator());
- return Places.nowNs() - t0;
+ return pardes.FrameStats.nowNs() - t0;
}
};
var report: std.ArrayList(u8) = .empty;
diff --git a/src/Tables.zig b/src/Tables.zig
index 44918559..765975dc 100644
--- a/src/Tables.zig
+++ b/src/Tables.zig
@@ -521,7 +521,7 @@ fn scanFrom(t: *Tables, gpa: std.mem.Allocator, content: []const u8, at: *Resume
var fence = at.fence;
var prev_blank = at.prev_blank;
var line = lineAt(content, at.at, at.n);
- const t0 = if (budget_ns > 0) panes.Places.nowNs() else 0;
+ const t0 = if (budget_ns > 0) pardes.FrameStats.nowNs() else 0;
var lines: usize = 0;
while (line) |l| : (lines += 1) {
if (l.n > stop) break;
@@ -1100,7 +1100,7 @@ test "zz tables timings on a big markdown file (TABLES_TIMES=<path>)" {
const io = testing.io;
const bytes = try std.Io.Dir.cwd().readFileAlloc(io, path, testing.allocator, .limited(16 << 20));
defer testing.allocator.free(bytes);
- const now = panes.Places.nowNs;
+ const now = pardes.FrameStats.nowNs;
var report: std.ArrayList(u8) = .empty;
defer report.deinit(testing.allocator);
{
@@ -1153,11 +1153,11 @@ test "zz tables timings on a big markdown file (TABLES_TIMES=<path>)" {
_ = try p.render(frame.allocator());
const Clock = struct {
fn step(pp: *Pardes, fr: *std.heap.ArenaAllocator, ev: pardes.Event) !u64 {
- const t0 = panes.Places.nowNs();
+ const t0 = pardes.FrameStats.nowNs();
pp.update(ev);
_ = fr.reset(.retain_capacity);
_ = try pp.render(fr.allocator());
- return panes.Places.nowNs() - t0;
+ return pardes.FrameStats.nowNs() - t0;
}
};
var sum: u64 = 0;