From 8d891fb05c05662f2e0a395f749edcccddee35a3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 8 Feb 2024 21:28:14 -0800 Subject: [PATCH] terminal: fast-path ASCII on char width --- src/terminal/Terminal.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index f9f55ae83..4d5616003 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -870,8 +870,10 @@ pub fn print(self: *Terminal, c: u21) !void { } // Determine the width of this character so we can handle - // non-single-width characters properly. - const width: usize = @intCast(unicode.table.get(c).width); + // non-single-width characters properly. We have a fast-path for + // byte-sized characters since they're so common. We can ignore + // control characters because they're always filtered prior. + const width: usize = if (c <= 0xFF) 1 else @intCast(unicode.table.get(c).width); // Note: it is possible to have a width of "3" and a width of "-1" // from ziglyph. We should look into those cases and handle them