From 53c8d3d4c3c9673c0070eceb652326193fb32012 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:55:53 -0300 Subject: pdf: searchRows prints each hit's row straight into the caller's buffer, where it printed each (up to 512) into the arena and copied it over; a row that does not fit ends the list as it did, and look.zig no longer hands it an arena Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/look.zig | 1 - src/pdf_view.zig | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/look.zig b/src/look.zig index a230d740..a4a64b14 100644 --- a/src/look.zig +++ b/src/look.zig @@ -598,7 +598,6 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart, const found = try panes.Pdf.searchRows( &pane.pdf.?, p.pdf_gpa, - arena, pat, start == .cursor, out, diff --git a/src/pdf_view.zig b/src/pdf_view.zig index d357b9cb..a0a48178 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -1169,7 +1169,6 @@ pub fn visibleText( pub fn searchRows( state: *State, gpa: std.mem.Allocator, - arena: std.mem.Allocator, pattern: []const u8, from_cursor: bool, out: []u8, @@ -1203,15 +1202,14 @@ pub fn searchRows( for (0..found.hit_count) |hit_index| { if (result.rows >= max_hits) break; - const line = try std.fmt.allocPrint(arena, "{s}:{d}:{d} {s}\n", .{ + // A row that does not fit ends the list. + const line = std.fmt.bufPrint(out[result.bytes..], "{s}:{d}:{d} {s}\n", .{ shown, page + 1, hit_index + 1, snippet, - }); - if (line.len > out.len - result.bytes) return result; + }) catch return result; if (from_cursor and (page < state.page or (page == state.page and cursor_hit != null and hit_index <= cursor_hit.?))) result.anchor = result.rows; - @memcpy(out[result.bytes..][0..line.len], line); result.bytes += line.len; result.rows += 1; } -- cgit v1.3