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.
This commit is contained in:
Jon Parise
2026-08-19 17:02:45 -04:00
parent 3e7230bf5d
commit 5a8921ecb5

View File

@@ -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),
});