From 2504b38647653db091aa7709afcea0dbe75f7a95 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:31:19 -0300 Subject: normal, modal, File, edit: small ones: tryFind inlined (its clamp never bound), the smart-case haystack is allocLowerString, the two WordTargets nothing produces go, File.lineCount is modal.cursorLineCount's alias, and pasteRegister and ClipRequest share one Paste enum Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/normal.zig | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'src/normal.zig') diff --git a/src/normal.zig b/src/normal.zig index ee39531d..48ac636c 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -94,11 +94,7 @@ pub fn applySelRegex(p: *Pardes, pane: *Pane, t: *Text, pat: []const u8, mode: m var hay_all = text; if (for (pat) |c| { if (std.ascii.isUpper(c)) break false; - } else true) { - const low = p.scratch.allocator().dupe(u8, text) catch return; - for (low) |*c| c.* = std.ascii.toLower(c.*); - hay_all = low; - } + } else true) hay_all = std.ascii.allocLowerString(p.scratch.allocator(), text) catch return; for (snap) |r| { const from = @min(r.anchor, r.head); const to = @min(@max(r.anchor, r.head), text.len); @@ -162,11 +158,7 @@ fn searchStep(p: *Pardes, t: *Text, text: []const u8, direction: modal.Normal.Di var hay = text; if (for (pat) |c| { if (std.ascii.isUpper(c)) break false; - } else true) { - const lower = p.scratch.allocator().dupe(u8, text) catch return; - for (lower) |*c| c.* = std.ascii.toLower(c.*); - hay = lower; - } + } else true) hay = std.ascii.allocLowerString(p.scratch.allocator(), text) catch return; for (0..count) |_| { var ranges: [Text.max_selections]modal.Selection = undefined; const got = t.ranges(text, 0, &ranges); @@ -175,9 +167,9 @@ fn searchStep(p: *Pardes, t: *Text, text: []const u8, direction: modal.Normal.Di const to = @max(old.anchor, old.head); var wrapped = false; const found = (if (direction == .forward) blk: { - if (tryFind(&re, hay, to, hay.len)) |h| break :blk h; + if (re.find(hay, to, hay.len)) |h| break :blk h; wrapped = true; - break :blk tryFind(&re, hay, 0, hay.len); + break :blk re.find(hay, 0, hay.len); } else blk: { if (lastMatch(&re, hay, 0, from)) |h| break :blk h; wrapped = true; @@ -203,15 +195,11 @@ fn searchStep(p: *Pardes, t: *Text, text: []const u8, direction: modal.Normal.Di t.show(); } -fn tryFind(re: *SearchRegex, hay: []const u8, from: usize, to: usize) ?regexp.Regex.Match { - return re.find(hay, @min(from, hay.len), to); -} - fn lastMatch(re: *SearchRegex, hay: []const u8, from: usize, to: usize) ?regexp.Regex.Match { var last: ?regexp.Regex.Match = null; var at = from; while (at <= to) { - const found = tryFind(re, hay, at, to) orelse break; + const found = re.find(hay, at, to) orelse break; last = found; at = if (found.end > found.start) found.end else modal.nextGrapheme(hay, found.end); if (at <= found.start) break; -- cgit v1.3