From c4f3749c058121ba086a851188691e7ae40d2018 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 12:22:50 -0300 Subject: a row's last byte deep in a long line is found walking to its column only: rawAtDisplay no longer measures the rest of the line first File.rawAtDisplay took the display width of the whole rest of the line before walking to the column, so every byteAtRowDisplay on a row of a 2 MB line measured 2 MB: a selection whose head is deep in such a line, with the line's first rows in view, drew in 20 ms (Debug) instead of 0.1. Only a line that ends before the column is measured whole now, and it is short. Same answers, at the end and past it included (the test). The perf gate's deep-sel cell had never drawn that line: its view, set by ensureCursorVisible from the last frame's wrap map, stopped six lines short of it. With the map made for the view as it is (File.geometry, next commit) the line is in view and the walk showed. Co-Authored-By: Claude Opus 5.5 --- src/File.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/File.zig') diff --git a/src/File.zig b/src/File.zig index 6df49c98..e4bca000 100644 --- a/src/File.zig +++ b/src/File.zig @@ -509,10 +509,13 @@ pub fn rawDisplayCol(line_text: []const u8, raw_col: usize) usize { return displayWidth(line_text[0..bounded]) +| (raw_col -| line_text.len); } +/// Walked only as far as the column: a row's last byte, a million bytes +/// into a line, is found without measuring the rest of it. Only a line +/// that ends before the column is measured whole (it is short). pub fn rawAtDisplay(line_text: []const u8, display_col: usize) usize { - const width = displayWidth(line_text); - if (display_col > width) return line_text.len +| (display_col - width); - return byteAtDisplay(line_text, display_col); + const at = byteAtDisplay(line_text, display_col); + if (at < line_text.len) return at; + return line_text.len +| (display_col -| displayWidth(line_text)); } pub fn byteAtDisplayFrom(line_text: []const u8, from_raw: usize, display_col: usize) usize { -- cgit v1.3