diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:55:35 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:02:08 -0300 |
| commit | aac802c58937053a200b0392843195b128a21172 (patch) | |
| tree | 67ea31d4f5be6eb5b8ef8ea9ef301e3874b1cebd | |
| parent | 7fb385cb7882f79bd448250b176f2d3a81de64f6 (diff) | |
| download | pardes-aac802c58937053a200b0392843195b128a21172.tar.gz pardes-aac802c58937053a200b0392843195b128a21172.zip | |
pdf: every by-value copy of a pane's PDF state (about 39 KB, its 256 raster slots) taken to read a field or two is a pointer capture, in panes, edit, mouse, tagline, look, exec, the core, 9P ctl, fs, draw, macos and the sections bench; the hot one is pdf_view.moving, which Pardes.continuous asks on every pass of the shell loop and which copied every PDF pane's state each time
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | src/draw.zig | 2 | ||||
| -rw-r--r-- | src/edit.zig | 4 | ||||
| -rw-r--r-- | src/exec.zig | 2 | ||||
| -rw-r--r-- | src/fs.zig | 2 | ||||
| -rw-r--r-- | src/look.zig | 6 | ||||
| -rw-r--r-- | src/macos.zig | 2 | ||||
| -rw-r--r-- | src/mouse.zig | 2 | ||||
| -rw-r--r-- | src/ninep/ctl.zig | 2 | ||||
| -rw-r--r-- | src/panes.zig | 10 | ||||
| -rw-r--r-- | src/pardes.zig | 2 | ||||
| -rw-r--r-- | src/pdf_view.zig | 2 | ||||
| -rw-r--r-- | src/tagline.zig | 2 | ||||
| -rw-r--r-- | test/pdf_sections_bench.zig | 2 |
13 files changed, 20 insertions, 20 deletions
diff --git a/src/draw.zig b/src/draw.zig index 1e17df3d..518f0800 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -1071,7 +1071,7 @@ fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { start = std.mem.lastIndexOf(u8, tag[0..@min(prefix_len, tag.len)], state.path) orelse return null; break :blk state.path; } else if (comptime pdf_enabled) blk: { - break :blk if (pane.pdf) |state| state.path else return null; + break :blk if (pane.pdf) |*state| state.path else return null; } else return null; const basename = if (std.mem.lastIndexOfScalar(u8, name, '/')) |slash| slash + 1 else 0; if (basename == name.len) return null; diff --git a/src/edit.zig b/src/edit.zig index 74dd0d1d..85ace33f 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -182,7 +182,7 @@ fn pasteInto(p: *Pardes, t: *Text, bytes: []const u8) void { } pub fn clipYank(p: *Pardes, pane: *Pane, main_only: bool) void { - if (comptime pdf_enabled) if (pane.pdf) |pv| { + if (comptime pdf_enabled) if (pane.pdf) |*pv| { if (pv.selection_text.len > 0) setClipboard(p, pv.selection_text); return; }; @@ -360,7 +360,7 @@ pub fn spanHas(r: i32, c: i32, ar: i32, ac: i32, br: i32, bc: i32) bool { /// the active modal selection as text (v range or x lines), if any pub fn currentSelText(p: *Pardes, pane: *Pane) ?[]const u8 { - if (comptime pdf_enabled) if (p.native_images) if (pane.pdf) |pv| + if (comptime pdf_enabled) if (p.native_images) if (pane.pdf) |*pv| if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text; if (pane.body.vsel.active) return vselText(p, &pane.body); if (!pane.body.msel.active) return null; diff --git a/src/exec.zig b/src/exec.zig index 4706d11a..27effda0 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -277,7 +277,7 @@ fn heldPane(p: *Pardes, first: usize, k: usize) ?*Pane { pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { for (0..p.panes.len + 2) |k| { const t = heldPane(p, first, k) orelse continue; - if (comptime pdf_enabled) if (p.native_images) if (t.pdf) |pv| { + if (comptime pdf_enabled) if (p.native_images) if (t.pdf) |*pv| { if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text; }; @@ -1481,7 +1481,7 @@ pub fn unmount(p: *Pardes, name: []const u8) !void { const pane = slot orelse continue; const paths = [_][]const u8{ if (pane.file) |file| file.path else "", - if (comptime pardes.pdf_enabled) (if (pane.pdf) |pdf| pdf.path else "") else "", + if (comptime pardes.pdf_enabled) (if (pane.pdf) |*pdf| pdf.path else "") else "", if (pane.image) |image| image.path else "", Pardes.paneDir(pane), }; diff --git a/src/look.zig b/src/look.zig index 1f81d6ec..a230d740 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1046,7 +1046,7 @@ fn openPaneTarget(p: *const Pardes, path: []const u8, at: Spot) ?Target { if (tt.image) |iv| if (std.mem.eql(u8, iv.path, path)) { return .{ .pane = .{ .id = i, .at = .{} } }; }; - if (comptime pdf_enabled) if (tt.pdf) |pv| if (std.mem.eql(u8, pv.path, path)) { + if (comptime pdf_enabled) if (tt.pdf) |*pv| if (std.mem.eql(u8, pv.path, path)) { return .{ .pane = .{ .id = i, .at = at } }; }; const ff = if (tt.file) |*f| f else continue; @@ -1149,7 +1149,7 @@ fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 { if (target.id >= p.panes.len) return null; const pane = p.panes[target.id] orelse return null; if (pane.file) |file| return locationText(p, file.path, target.at); - if (comptime pdf_enabled) if (pane.pdf) |doc| return locationText(p, doc.path, target.at); + if (comptime pdf_enabled) if (pane.pdf) |*doc| return locationText(p, doc.path, target.at); if (pane.image) |iv| return locationText(p, iv.path, target.at); var path: [32]u8 = undefined; return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{pane.serial}) catch return null, target.at); @@ -1159,7 +1159,7 @@ fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 { pub fn pdfLinkLocation(p: *Pardes, pane: *const Pane, link: if (pdf_enabled) pdf.Link else void) ?[]const u8 { if (comptime !pdf_enabled) return null; - const state = pane.pdf orelse return null; + const state = &(pane.pdf orelse return null); const id = p.paneIdOf(pane) orelse return null; return switch (link.destination) { .none => null, diff --git a/src/macos.zig b/src/macos.zig index e69a2fbe..60f9e00e 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -880,7 +880,7 @@ fn watchInitialGeneration(st: *State, pane: u8, path: []const u8) ?file_watch.Ge const value = st.core.panes[pane] orelse return null; if (value.file) |file| if (std.mem.eql(u8, file.path, path)) return .{ .text = std.hash.Wyhash.hash(0, file.content) }; - if (comptime pardes.pdf_enabled) if (value.pdf) |pdf| if (std.mem.eql(u8, pdf.path, path)) + if (comptime pardes.pdf_enabled) if (value.pdf) |*pdf| if (std.mem.eql(u8, pdf.path, path)) return .{ .pdf = null }; return null; } diff --git a/src/mouse.zig b/src/mouse.zig index 69d1456e..51a566d9 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -1395,7 +1395,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { fn chordCutPaste(p: *Pardes, cut: bool) void { const s = &p.drag.select; const pane = p.panes[s.id] orelse return; - if (comptime pdf_enabled) if (pane.pdf) |pv| { + if (comptime pdf_enabled) if (pane.pdf) |*pv| { if (!s.chorded) { s.chorded = true; pane.sel[sel_slot].state = .none; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 0fb92b1a..7c566f23 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -441,7 +441,7 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 { // Then what its tag does not say: Collapse, and a PDF's PdfFit and // PdfTint, in the words they take. if (pane.collapsed) w.writeAll("collapsed ") catch {}; - if (comptime pardes.pdf_enabled) if (pane.pdf) |pv| w.print("fit:{s} tint:{s} ", .{ @tagName(pv.fit), @tagName(pv.tint) }) catch {}; + if (comptime pardes.pdf_enabled) if (pane.pdf) |*pv| w.print("fit:{s} tint:{s} ", .{ @tagName(pv.fit), @tagName(pv.tint) }) catch {}; // Last, the body's mode, which the tag shows as a box: helix's select // is normal mode extending. w.print("mode:{s} ", .{if (pane.body.mode == .normal and pane.body.select) "select" else @tagName(pane.body.mode)}) catch {}; diff --git a/src/panes.zig b/src/panes.zig index f4b25929..f7a3cf8a 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -509,12 +509,12 @@ pub const Pane = struct { } pub fn pdfPath(pane: *const Pane) ?[]const u8 { - if (comptime Pdf.enabled) if (pane.pdf) |pv| return pv.path; + if (comptime Pdf.enabled) if (pane.pdf) |*pv| return pv.path; return null; } pub fn pdfPage(pane: *const Pane) ?usize { - if (comptime Pdf.enabled) if (pane.pdf) |pv| return pv.page; + if (comptime Pdf.enabled) if (pane.pdf) |*pv| return pv.page; return null; } @@ -538,7 +538,7 @@ pub const Pane = struct { /// current scroll offset: file top line, or the scrollback offset pub fn scroll(pane: *Pane) i32 { if (pane.file) |f| return @intCast(f.scroll); - if (comptime Pdf.enabled) if (pane.pdf) |pv| return @intCast(pv.text_scroll); + if (comptime Pdf.enabled) if (pane.pdf) |*pv| return @intCast(pv.text_scroll); return pane.surfRow(terminal.gridOffset(pane) + pane.pan); } @@ -637,7 +637,7 @@ pub const Pane = struct { to = @min(to, if (off == 0 and pane.textFits()) @max(pane.body.cur_row, lines - 1 - @intFromBool(std.mem.endsWith(u8, f.content, "\n"))) else lines - 1); } if (comptime Pdf.enabled) { - if (pane.pdf) |pv| + if (pane.pdf) |*pv| to = @min(to, @as(i32, @intCast(modal.lineCount(pv.text) -| 1))); } pane.scrollBy(@max(0, to - last)); @@ -684,7 +684,7 @@ pub const Pane = struct { pub fn hasPdfSelection(pane: *const Pane) bool { return if (comptime Pdf.enabled) - if (pane.pdf) |pv| pv.selection != null and pv.selection_text.len > 0 else false + if (pane.pdf) |*pv| pv.selection != null and pv.selection_text.len > 0 else false else false; } diff --git a/src/pardes.zig b/src/pardes.zig index 2596e069..14c6bd98 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -6331,7 +6331,7 @@ pub const Pardes = struct { .none => {}, } if (pane.file) |f| return panes.Dir.ofName(f.path); - if (comptime pdf_enabled) if (pane.pdf) |pv| + if (comptime pdf_enabled) if (pane.pdf) |*pv| return std.fs.path.dirname(pv.path) orelse "/"; if (pane.image) |iv| return std.fs.path.dirname(iv.path) orelse "/"; return pane.cwdSlice(); diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 71433729..d357b9cb 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -3463,7 +3463,7 @@ fn stripAt(state: *State, view: Viewport, motion: pardes.animation.Motion, now_n /// A PDF strip is still on its way to where the core stands. pub fn moving(core: *const pardes.Pardes) bool { if (comptime !enabled) return false; - for (core.panes) |slot| if (slot) |pane| if (pane.pdf) |state| if (state.follow.moving()) return true; + for (core.panes) |slot| if (slot) |pane| if (pane.pdf) |*state| if (state.follow.moving()) return true; return false; } diff --git a/src/tagline.zig b/src/tagline.zig index e7194981..73683c1e 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -113,7 +113,7 @@ fn shownDir(arena: std.mem.Allocator, pane: *Pane) ![]const u8 { /// PDF's page, a terminal's directory -- without the space that parts it /// from the tag's own text. It is never stored, and never edited. pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 { - if (comptime pdf_enabled) if (pane.pdf) |pv| + if (comptime pdf_enabled) if (pane.pdf) |*pv| return std.fmt.allocPrint(arena, "{s} [{d}/{d}]", .{ pv.path, pv.page + 1, pv.page_count }); // What is drawn: with no graphics, glyph art whatever `Petscii` says. if (pane.image) |*state| return panes.Image.tagPrefix(arena, state, state.glyph_art or !p.native_images); diff --git a/test/pdf_sections_bench.zig b/test/pdf_sections_bench.zig index 47b74018..2796910c 100644 --- a/test/pdf_sections_bench.zig +++ b/test/pdf_sections_bench.zig @@ -336,7 +336,7 @@ fn sectionsOutputIdentity(core: *pardes.Pardes) Identity { fn stepIdentity(core: *pardes.Pardes) Identity { var identity = sectionsOutputIdentity(core); const owner = core.panes[0].?; - const view = owner.pdf.?; + const view = &owner.pdf.?; identity.checksum = mix(identity.checksum, view.page); identity.checksum = mix(identity.checksum, @as(u64, @bitCast(view.document_scroll_y))); identity.checksum = mix(identity.checksum, owner.search_row orelse std.math.maxInt(usize)); |
