summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 00:22:27 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:00:59 -0300
commit1b12f7aadaf0e0a4570a5985900f61d0fb897f79 (patch)
tree2563f00aa47d3ef39ef1647482ba5d19bc1373a1 /src
parentb283824eed0703ae9b89f2af520354046146b855 (diff)
downloadpardes-1b12f7aadaf0e0a4570a5985900f61d0fb897f79.tar.gz
pardes-1b12f7aadaf0e0a4570a5985900f61d0fb897f79.zip
surface: a frame's images are a std.ArrayList(ImagePlace), where they were a slice of optionals grown by hand (appendImagePlace's doubling realloc, nimages beside it) whose slots were never null: every reader's `orelse continue` and `.?` go (gui, tui, terminal, TerminalImages, ninep/screen, test/pdf.zig, kitty and the two PDF benches); macos.zig's loop the same, passing ast-check but not built here
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
-rw-r--r--src/TerminalImages.zig8
-rw-r--r--src/draw.zig2
-rw-r--r--src/gui/gui.zig14
-rw-r--r--src/macos.zig11
-rw-r--r--src/ninep/screen.zig4
-rw-r--r--src/pardes.zig16
-rw-r--r--src/surface.zig3
-rw-r--r--src/terminal.zig14
-rw-r--r--src/tui/tui.zig10
9 files changed, 31 insertions, 51 deletions
diff --git a/src/TerminalImages.zig b/src/TerminalImages.zig
index f26b5852..ab8ee099 100644
--- a/src/TerminalImages.zig
+++ b/src/TerminalImages.zig
@@ -164,10 +164,10 @@ pub fn draw(
const ctx: Ctx = .{ .ti = ti, .p = p, .s = s, .pane = pane_id, .serial = serial, .tx = tx, .body_y = body_y, .cols = cols, .rows_of = rows_of, .cw = cw, .ch = ch, .pixels = pixels };
// Handed on lowest z first (the storage's order is a hash map's), the
// order a shell draws them in; equal z keeps the order they came in.
- const first = s.nimages;
- defer std.sort.insertion(?pardes.ImagePlace, s.images[first..s.nimages], {}, struct {
- fn lessThan(_: void, a: ?pardes.ImagePlace, b: ?pardes.ImagePlace) bool {
- return (if (a) |x| x.z else 0) < (if (b) |y| y.z else 0);
+ const first = s.images.items.len;
+ defer std.sort.insertion(pardes.ImagePlace, s.images.items[first..], {}, struct {
+ fn lessThan(_: void, a: pardes.ImagePlace, b: pardes.ImagePlace) bool {
+ return a.z < b.z;
}
}.lessThan);
diff --git a/src/draw.zig b/src/draw.zig
index 4f238942..1e17df3d 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -551,7 +551,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
if (p.drag == .move or p.drag == .column_move) s.pointer_shape = .box;
for (&s.body_layers) |*layer| layer.rows = 0;
for (&s.tag_layers) |*layer| layer.rows = 0;
- s.nimages = 0;
+ s.images.clearRetainingCapacity();
s.npanel_tracks = 0;
s.previous_cells = &.{};
s.previous_body_layers = &.{};
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index ac32ced4..00491aeb 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -6457,8 +6457,7 @@ fn clearNativeImages(g: *Gui) void {
}
fn surfaceHasNativeKey(surface: *const pardes.Surface, key: pardes.ImageCacheKey) bool {
- for (surface.images[0..surface.nimages]) |maybe| {
- const place = maybe orelse continue;
+ for (surface.images.items) |place| {
if (validImageBytes(place) != null and place.cacheKey().eql(key)) return true;
}
return false;
@@ -6474,9 +6473,8 @@ fn rememberPresentedImages(g: *Gui, gpa: std.mem.Allocator, surface: *const pard
var next: std.ArrayListUnmanaged(SavedImagePlace) = .empty;
var adopted = false;
defer if (!adopted) next.deinit(gpa);
- next.ensureTotalCapacity(gpa, surface.nimages) catch return;
- for (surface.images[0..surface.nimages]) |maybe| {
- const place = maybe orelse continue;
+ next.ensureTotalCapacity(gpa, surface.images.items.len) catch return;
+ for (surface.images.items) |place| {
if (validImageBytes(place) == null or !g.native_images.contains(place.cacheKey())) continue;
next.appendAssumeCapacity(SavedImagePlace.from(place));
}
@@ -6753,8 +6751,7 @@ fn prepareNativeImages(
sw: u32,
sh: u32,
) bool {
- for (surface.images[0..surface.nimages]) |maybe| {
- const place = maybe orelse continue;
+ for (surface.images.items) |place| {
if (validImageBytes(place) == null) continue;
uploadNativeTexture(g, gpa, cmd, place) catch continue;
}
@@ -6794,8 +6791,7 @@ fn prepareNativeImages(
}
if (track == null or track.?.phase != .closing) {
- for (surface.images[0..surface.nimages]) |maybe| {
- const current = maybe orelse continue;
+ for (surface.images.items) |current| {
if (validImageBytes(current) == null or
groupOf(groups, current.serial) != group_index) continue;
const saved = SavedImagePlace.from(current);
diff --git a/src/macos.zig b/src/macos.zig
index bc906dea..e69a2fbe 100644
--- a/src/macos.zig
+++ b/src/macos.zig
@@ -1756,16 +1756,15 @@ fn encodeChanged(diff: pardes.PanelCellDiff) u8 {
fn collectImages(st: *State, surface: *const pardes.Surface) void {
if (comptime !pardes.pdf_enabled) return;
- if (surface.nimages == 0) return;
- if (st.images.len < surface.nimages) {
+ if (surface.images.items.len == 0) return;
+ if (st.images.len < surface.images.items.len) {
const resized = if (st.images.len == 0)
- st.gpa.alloc(Image, surface.nimages)
+ st.gpa.alloc(Image, surface.images.items.len)
else
- st.gpa.realloc(st.images, surface.nimages);
+ st.gpa.realloc(st.images, surface.images.items.len);
st.images = resized catch return;
}
- for (surface.images[0..surface.nimages]) |maybe| {
- const place = maybe orelse continue;
+ for (surface.images.items) |place| {
if (place.iw == 0 or place.ih == 0 or place.rgba.len == 0) continue;
const geometry = place.native.geometry orelse image.NativeGeometry{
.src = .{ .x = 0, .y = 0, .w = @intCast(place.iw), .h = @intCast(place.ih) },
diff --git a/src/ninep/screen.zig b/src/ninep/screen.zig
index c0251d80..95fe50a7 100644
--- a/src/ninep/screen.zig
+++ b/src/ninep/screen.zig
@@ -293,8 +293,8 @@ test "screen inspection preserves acknowledged presentation and the next real fr
try testing.expectEqualDeep(expected.cell_diffs, actual.cell_diffs);
try testing.expectEqual(expected.previous_cells.len, actual.previous_cells.len);
try testing.expectEqual(expected.cells.len, actual.cells.len);
- try testing.expectEqual(@as(usize, 0), expected.nimages);
- try testing.expectEqual(@as(usize, 0), actual.nimages);
+ try testing.expectEqual(@as(usize, 0), expected.images.items.len);
+ try testing.expectEqual(@as(usize, 0), actual.images.items.len);
for (expected.cells, actual.cells) |*left, *right| try testing.expect(left.visuallyEqual(right));
for (expected.previous_cells, actual.previous_cells) |*left, *right| try testing.expect(left.visuallyEqual(right));
if (phase == 1 and transition != .off) try testing.expect(expected.panelTracks().len > 0);
diff --git a/src/pardes.zig b/src/pardes.zig
index 11cb762a..fb26840b 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -4478,7 +4478,7 @@ pub const Pardes = struct {
for (&p.surface.body_layers) |*layer| gpa.free(layer.cells);
for (&p.surface.tag_layers) |*layer| gpa.free(layer.cells);
p.presentation.deinit(gpa);
- if (p.surface.images.len > 0) gpa.free(p.surface.images);
+ p.surface.images.deinit(gpa);
gpa.destroy(p);
}
@@ -7573,19 +7573,7 @@ pub const Pardes = struct {
pub const render = draw.render;
pub fn appendImagePlace(p: *Pardes, place: ImagePlace) bool {
- const s = &p.surface;
- if (s.nimages == s.images.len) {
- const old_len = s.images.len;
- const new_len = @max(@as(usize, 4), std.math.mul(usize, @max(old_len, 1), 2) catch return false);
- const grown = if (old_len == 0)
- p.gpa.alloc(?ImagePlace, new_len) catch return false
- else
- p.gpa.realloc(s.images, new_len) catch return false;
- @memset(grown[old_len..], null);
- s.images = grown;
- }
- s.images[s.nimages] = place;
- s.nimages += 1;
+ p.surface.images.append(p.gpa, place) catch return false;
return true;
}
};
diff --git a/src/surface.zig b/src/surface.zig
index f5afdd98..3b99f517 100644
--- a/src/surface.zig
+++ b/src/surface.zig
@@ -499,8 +499,7 @@ pub const Surface = struct {
cells: []Cell = &.{},
/// bar: draw an insert-style thin cursor instead of the block
cursor: ?struct { x: u16, y: u16, bar: bool = false } = null,
- images: []?ImagePlace = &.{},
- nimages: usize = 0,
+ images: std.ArrayList(ImagePlace) = .empty,
panel_tracks: [MAX_PANES * 2]animation.Track = undefined,
npanel_tracks: usize = 0,
previous_cells: []const Cell = &.{},
diff --git a/src/terminal.zig b/src/terminal.zig
index 2bd41030..04e4f233 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -3316,8 +3316,8 @@ inline fn kittyTransmit(comptime extra: []const u8) []const u8 {
};
}
-fn imagePlaces(s: *const Surface) []const ?pardes.ImagePlace {
- return s.images[0..s.nimages];
+fn imagePlaces(s: *const Surface) []const pardes.ImagePlace {
+ return s.images.items;
}
test "a terminal's kitty graphics image is drawn where its program placed it, and a delete takes it away" {
@@ -3336,7 +3336,7 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an
var s = try p.render(frame.allocator());
const places = imagePlaces(s);
try std.testing.expectEqual(@as(usize, 1), places.len);
- const place = places[0].?;
+ const place = places[0];
const r = p.rects[0];
try std.testing.expect(place.native.exact);
try std.testing.expectEqual(@as(u32, 7), place.native.page);
@@ -3356,7 +3356,7 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[24;1H\n\n" } });
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
- try std.testing.expectEqual(p.bodyTop(pane, r), imagePlaces(s)[0].?.y);
+ try std.testing.expectEqual(p.bodyTop(pane, r), imagePlaces(s)[0].y);
p.update(.{ .output = .{ .pane = 0, .bytes = "\n" } });
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
@@ -3472,9 +3472,9 @@ test "a virtual kitty placement shows through its placeholder cells, which draw
const r = p.rects[0];
const tx = r.x + config.GUTTER;
const y = p.bodyTop(pane, r) + 1;
- try std.testing.expectEqual(tx + 2, places[0].?.x);
- try std.testing.expectEqual(y, places[0].?.y);
- try std.testing.expectEqual(@as(u16, 2), places[0].?.w);
+ try std.testing.expectEqual(tx + 2, places[0].x);
+ try std.testing.expectEqual(y, places[0].y);
+ try std.testing.expectEqual(@as(u16, 2), places[0].w);
try std.testing.expectEqualStrings(" ", s.at(tx + 2, y).grapheme());
try std.testing.expectEqualStrings(" ", s.at(tx + 3, y).grapheme());
try std.testing.expectEqualStrings("X", s.at(tx + 4, y).grapheme());
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index e7fde434..0230e7a9 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -1191,8 +1191,8 @@ test "host watch closes initial race and reloads rename-over PDF while idle" {
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
const surface = try core.render(frame.allocator());
- try std.testing.expect(surface.nimages > 0);
- try std.testing.expectEqual(@as(u32, 0), surface.images[0].?.native.page);
+ try std.testing.expect(surface.images.items.len > 0);
+ try std.testing.expectEqual(@as(u32, 0), surface.images.items[0].native.page);
}
fn kittyImageRepresentable(place: pardes.ImagePlace) bool {
@@ -1201,8 +1201,7 @@ fn kittyImageRepresentable(place: pardes.ImagePlace) bool {
}
fn surfaceHasKittyKey(surface: *const pardes.Surface, key: pardes.ImageCacheKey) bool {
- for (surface.images[0..surface.nimages]) |maybe| {
- const place = maybe orelse continue;
+ for (surface.images.items) |place| {
if (comptime pardes.pdf_enabled) if (!kittyImageRepresentable(place)) continue;
if (place.cacheKey().eql(key)) return true;
}
@@ -2838,8 +2837,7 @@ const Shell = struct {
paintCells(win, trailed.cells, trailed.cols, trailed.rows);
if (s.remote) |c| if (c.link.notice_len > 0) noticeLine(win, c.link.notice(), trailed.cols, trailed.rows);
tz_cells.end();
- for (surface.images[0..surface.nimages]) |maybe| {
- const place = maybe orelse continue;
+ for (surface.images.items) |place| {
if (panel_compositor.hidesAttachment(surface.panelTracks(), place.serial)) continue;
if (comptime pardes.pdf_enabled) {
if (!kittyImageRepresentable(place)) continue;