diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 22:58:39 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-04 22:58:39 -0300 |
| commit | e57b26fc1406a2f1e6541558d5ebd35d7ef54b1d (patch) | |
| tree | 4e22f4b7d475193cec565811a4e5d3961999d3c3 /src/Query.zig | |
| parent | 7f0e75d6e44e0371e204528792a13f9cac5f2b76 (diff) | |
| download | pardes-e57b26fc1406a2f1e6541558d5ebd35d7ef54b1d.tar.gz pardes-e57b26fc1406a2f1e6541558d5ebd35d7ef54b1d.zip | |
Places: one lineOf for the line a byte is on, std.sort.partitionPoint in place of five hand-written binary searches (firstFrom, paint's, tickOf's, and Query's lineOfOffset and writePlacesRows', the latter two the same search as tickOf's)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/Query.zig')
| -rw-r--r-- | src/Query.zig | 24 |
1 files changed, 2 insertions, 22 deletions
diff --git a/src/Query.zig b/src/Query.zig index e34b1054..5fdfff2a 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -925,15 +925,7 @@ fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.Ar var decl_now: ?usize = null; var i: usize = @min(from, hits.len); // the line of the first, found in the index - var line: usize = if (i < hits.len) blk: { - var lo: usize = 0; - var hi = index.len; - while (lo < hi) { - const mid = lo + (hi - lo) / 2; - if (index[mid] <= hits[i].start) lo = mid + 1 else hi = mid; - } - break :blk lo -| 1; - } else 0; + var line: usize = if (i < hits.len) Places.lineOf(index, hits[i].start) else 0; // a window begins at a line's first place while (i > 0 and hits[i - 1].start >= index[line]) i -= 1; while (i < hits.len) { @@ -1032,7 +1024,7 @@ fn showPlacesCurrent(p: *Pardes, id: usize) void { // By line, not by the rows' place indices: the rows may lag the places // a tick while they are still being found. if (set.current) |c| if (c < set.hits.items.len) { - const at = lineOfOffset(p, &owner.file.?, set.hits.items[c].start) + 1; + const at = Places.lineOf(File.lineIndex(p.gpa, &owner.file.?) catch &.{}, set.hits.items[c].start) + 1; const rows = rp.file.?.location_rows; for (q.items.items, 0..) |it, i| { if (it.kind != .hit or it.serial != owner.serial or i + 1 >= rows.len) continue; @@ -1508,18 +1500,6 @@ fn caretTo(rp: *Pane, i: usize) void { if (r >= off + @as(i32, rp.rows)) rp.scrollBy(r - off - @as(i32, rp.rows) + 1) else if (r < off) rp.scrollBy(r - off); } -/// The line (0-based) of byte `at` of `f`'s text. -fn lineOfOffset(p: *Pardes, f: *File.State, at: usize) usize { - const index = File.lineIndex(p.gpa, f) catch return 0; - var lo: usize = 0; - var hi = index.len; - while (lo < hi) { - const mid = lo + (hi - lo) / 2; - if (index[mid] <= at) lo = mid + 1 else hi = mid; - } - return lo -| 1; -} - /// The first of pane `tp`'s places on line `line` (1-based), if any. fn placeOnLine(p: *Pardes, tp: *Pane, line: usize) ?usize { const f = &tp.file.?; |
