From 5a8921ecb5bcb0411825722b2b7010db8eb3f56a Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Wed, 19 Aug 2026 17:02:45 -0400 Subject: [PATCH] surface: keep clipboard content list on stack Use a two element stack-based buffer for the one or two ClipboardContent entries rather than the (arena-based) heap allocator. --- src/Surface.zig | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 7ef2038b8..c28fbd2f3 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2257,13 +2257,14 @@ fn copySelectionToClipboards( const ScreenFormatter = terminal.formatter.ScreenFormatter; var aw: std.Io.Writer.Allocating = .init(alloc); - var contents: std.ArrayList(apprt.ClipboardContent) = .empty; + var contents_buf: [2]apprt.ClipboardContent = undefined; + var contents: std.ArrayList(apprt.ClipboardContent) = .initBuffer(&contents_buf); switch (format) { .plain => { var formatter: ScreenFormatter = .init(self.io.terminal.screens.active, opts); formatter.content = .{ .selection = sel }; try formatter.format(&aw.writer); - try contents.append(alloc, .{ + contents.appendAssumeCapacity(.{ .mime = "text/plain", .data = try aw.toOwnedSliceSentinel(0), }); @@ -2280,7 +2281,7 @@ fn copySelectionToClipboards( // Note: We don't apply codepoint mappings to VT format since it contains // escape sequences that should be preserved as-is - try contents.append(alloc, .{ + contents.appendAssumeCapacity(.{ .mime = "text/plain", .data = try aw.toOwnedSliceSentinel(0), }); @@ -2297,7 +2298,7 @@ fn copySelectionToClipboards( // Note: We don't apply codepoint mappings to HTML format since HTML // has its own character encoding and entity system - try contents.append(alloc, .{ + contents.appendAssumeCapacity(.{ .mime = "text/html", .data = try aw.toOwnedSliceSentinel(0), }); @@ -2308,7 +2309,7 @@ fn copySelectionToClipboards( var formatter: ScreenFormatter = .init(self.io.terminal.screens.active, opts); formatter.content = .{ .selection = sel }; try formatter.format(&aw.writer); - try contents.append(alloc, .{ + contents.appendAssumeCapacity(.{ .mime = "text/plain", .data = try aw.toOwnedSliceSentinel(0), }); @@ -2331,7 +2332,7 @@ fn copySelectionToClipboards( try formatter.format(&aw.writer); // Note: We don't apply codepoint mappings to HTML format - try contents.append(alloc, .{ + contents.appendAssumeCapacity(.{ .mime = "text/html", .data = try aw.toOwnedSliceSentinel(0), });