diff options
| -rw-r--r-- | src/Finder.zig | 7 | ||||
| -rw-r--r-- | src/Names.zig | 19 |
2 files changed, 13 insertions, 13 deletions
diff --git a/src/Finder.zig b/src/Finder.zig index 511dbed3..0be40c24 100644 --- a/src/Finder.zig +++ b/src/Finder.zig @@ -55,7 +55,7 @@ pub fn place(f: *Finder, p: *Pardes, id: usize) bool { layout.insert(p, c, 0, id); pane.vweight = 1; pane.collapsed = false; - f.fold(p, c, id); + fold(p, c, id); // The oldest goes once there are too many: the bottom one, as the top // is always the newest. while (p.col_n[c] > max_results) { @@ -101,8 +101,7 @@ fn open(f: *Finder, p: *Pardes) ?usize { /// Fold every pane of finder column `c` but `top` (and what is attached /// to it, its +Preview) to its tag. -fn fold(f: *const Finder, p: *Pardes, c: usize, top: usize) void { - _ = f; +fn fold(p: *Pardes, c: usize, top: usize) void { layout.compute(p); for (p.col_panes[c][0..p.col_n[c]]) |k| { const pane = p.panes[k] orelse continue; @@ -133,7 +132,7 @@ pub fn raise(f: *Finder, p: *Pardes, id: usize) void { for (moved[0..n]) |k| layout.removePane(p, k); for (moved[0..n], 0..) |k, i| layout.insert(p, c, i, k); } - f.fold(p, c, id); + fold(p, c, id); } /// The column a pane asked for from the finder goes in (a row looked at, a diff --git a/src/Names.zig b/src/Names.zig index fed63f2e..a3fff314 100644 --- a/src/Names.zig +++ b/src/Names.zig @@ -161,7 +161,7 @@ pub fn rescore(n: *Names, gpa: std.mem.Allocator) void { } else break; const c = n.cands.items[i]; const key = n.bytes.items[c.start + c.key ..][0..c.key_len]; - const s = if (empty) 0 else match(q, key, n.lower.items[c.start + c.key ..][0..c.key_len], c.base, null, null, null); + const s = if (empty) 0 else match(q, key, n.lower.items[c.start + c.key ..][0..c.key_len], c.base, null, null); if (s) |score| n.hits.append(gpa, .{ .cand = i, .score = score }) catch break; // The clock every 256 candidates: reading it is not free either. if (!empty and count % 256 == 255 and pardes.tape.over(started, score_budget_ns)) break; @@ -187,7 +187,7 @@ pub fn row(n: *const Names, i: usize, marks: []u16, nmarks: *usize) []const u8 { const q = n.queryText(); if (std.mem.trim(u8, q, " ").len > 0) { const key = n.bytes.items[c.start + c.key ..][0..c.key_len]; - _ = match(q, key, n.lower.items[c.start + c.key ..][0..c.key_len], c.base, marks, nmarks, &dp_trace); + _ = match(q, key, n.lower.items[c.start + c.key ..][0..c.key_len], c.base, marks, nmarks); for (marks[0..nmarks.*]) |*m| m.* += c.key; } return n.bytes.items[c.start..][0..c.len]; @@ -233,8 +233,9 @@ fn bonusAt(text: []const u8, j: usize) i32 { /// `query`'s score against `text` (`lower` its lowercase copy, its /// basename from `base`), null if some term of it is not a subsequence of /// `text`. Terms split on spaces are ANDed; smart case per term. With -/// `marks`, the bytes matched are written there, ascending. -pub fn match(query: []const u8, text_in: []const u8, lower_in: []const u8, base: usize, marks: ?[]u16, marks_len: ?*usize, trace: ?[]i32) ?i32 { +/// `marks`, the bytes matched are written there, ascending (the table they +/// are backtracked through is `dp_trace`). +fn match(query: []const u8, text_in: []const u8, lower_in: []const u8, base: usize, marks: ?[]u16, marks_len: ?*usize) ?i32 { const text = text_in[0..@min(text_in.len, max_text)]; const lower = lower_in[0..text.len]; var total: i32 = 0; @@ -260,7 +261,7 @@ pub fn match(query: []const u8, text_in: []const u8, lower_in: []const u8, base: var prev = &dp_rows[0]; var cur = &dp_rows[1]; const width = text.len; - const keep = if (trace) |t| t.len >= m * width else false; + const keep = marks != null; for (0..m) |i| { var gapped: i32 = neg; // max over k <= j-2 of D[i-1][k], less the gap to j for (lo..end) |col| { @@ -276,7 +277,7 @@ pub fn match(query: []const u8, text_in: []const u8, lower_in: []const u8, base: } } cur[col] = best; - if (keep) trace.?[i * width + col] = best; + if (keep) dp_trace[i * width + col] = best; } const t = prev; prev = cur; @@ -291,9 +292,9 @@ pub fn match(query: []const u8, text_in: []const u8, lower_in: []const u8, base: if (best <= neg) return null; total += best; // Back from the best end, the place each character was matched at. - if (keep and marks != null) { + if (keep) { const out = marks.?; - const t = trace.?; + const t = &dp_trace; var i = m; var col = at; while (i > 0) { @@ -345,7 +346,7 @@ fn topFor(q: []const u8) []const u8 { var best_score: i32 = std.math.minInt(i32); for (test_paths) |path| { var low: [256]u8 = undefined; - const s = match(q, path, std.ascii.lowerString(&low, path), baseOf(path), null, null, null) orelse continue; + const s = match(q, path, std.ascii.lowerString(&low, path), baseOf(path), null, null) orelse continue; if (s > best_score or (s == best_score and path.len < best.?.len)) { best = path; best_score = s; |
