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.
This commit is contained in:
Uzair Aftab
2026-08-02 23:11:20 +02:00
parent 6837d7027f
commit c992658b29

View File

@@ -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",