From c11fe5486f7c1f0aa346b8f0a23ea0fcedf79433 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Mon, 3 Aug 2026 13:18:36 -0400 Subject: [PATCH] core: avoid copying OSC 52 clipboard responses OSC 52 clipboard reads built their response in an allocated buffer and then passed it through Message.writeReq, which allocated a second copy for large responses. Instead, transfer the allocated response directly using .write_alloc. Small responses now retain their initial allocation until the IO thread consumes them instead of being copied inline and freed immediately. Their allocation count is unchanged, while large responses improve from two allocations to one. Both cases avoid the additional copy. --- src/Surface.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 61aaa34d1..fc83e81f3 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -5974,8 +5974,8 @@ fn completeClipboardReadOSC52( // This must hold the base64 encoded data PLUS the OSC code surrounding it. const enc = std.base64.standard.Encoder; const size = enc.calcSize(data.len); - var buf = try self.alloc.alloc(u8, size + 9); // const for OSC - defer self.alloc.free(buf); + const buf = try self.alloc.alloc(u8, size + 9); // const for OSC + errdefer self.alloc.free(buf); const kind: u8 = switch (clipboard_type) { .standard => 'c', @@ -5993,10 +5993,10 @@ fn completeClipboardReadOSC52( const encoded = enc.encode(buf[prefix.len..], data); assert(encoded.len == size); - self.queueIo(try termio.Message.writeReq( - self.alloc, - buf, - ), .unlocked); + self.queueIo(.{ .write_alloc = .{ + .alloc = self.alloc, + .data = buf, + } }, .unlocked); } fn showDesktopNotification(self: *Surface, title: [:0]const u8, body: [:0]const u8) !void {