From c992658b2994a560b052f79b241e4cd02df843c5 Mon Sep 17 00:00:00 2001 From: Uzair Aftab Date: Sun, 2 Aug 2026 23:11:20 +0200 Subject: [PATCH] terminal/osc: decode OSC 52 base64 with the SIMD decoder OSC 52 clipboard writes decoded their base64 payload with the scalar std implementation while Kitty graphics payloads already used the SIMD decoder in src/simd. Move clipboard path to use the same SIMD decoder. The encode side of the read reply stays scalar since the codebase has no SIMD encoder. 3.3x faster on a 4KB-payload decode micro-benchmark. --- src/terminal/stream_terminal.zig | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/terminal/stream_terminal.zig b/src/terminal/stream_terminal.zig index a2db0c7ee..72daffb15 100644 --- a/src/terminal/stream_terminal.zig +++ b/src/terminal/stream_terminal.zig @@ -16,6 +16,7 @@ const osc = @import("osc.zig"); const osc_color = @import("osc/parsers/color.zig"); const kitty_color = @import("kitty/color.zig"); const size_report = @import("size_report.zig"); +const simd = @import("../simd/main.zig"); const Terminal = @import("Terminal.zig"); const log = std.log.scoped(.stream_terminal); @@ -440,12 +441,13 @@ pub const Handler = struct { return; } - const decoder = std.base64.standard.Decoder; - const decoded_len = try decoder.calcSizeForSlice(data); + // Decode the base64 payload with the SIMD decoder (the same one + // used for Kitty graphics payloads) rather than the scalar std + // implementation; clipboard payloads can be megabytes. const alloc = self.terminal.gpa(); - const decoded = try alloc.alloc(u8, decoded_len); - defer alloc.free(decoded); - try decoder.decode(decoded, data); + const buf = try alloc.alloc(u8, simd.base64.maxLen(data)); + defer alloc.free(buf); + const decoded = try simd.base64.decode(data, buf); const contents = [_]clipboard.Content{.{ .mime = "text/plain",