From 8f9616c2308fe7bb9a14c7ff0bfa67dfe701bea2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 6 Aug 2020 17:57:57 +0530 Subject: [PATCH] Speed up wcwidth_std in the common case --- gen-wcwidth.py | 1 + kitty/wcwidth-std.h | 1 + 2 files changed, 2 insertions(+) diff --git a/gen-wcwidth.py b/gen-wcwidth.py index ad96bf340..a9fdd9da1 100755 --- a/gen-wcwidth.py +++ b/gen-wcwidth.py @@ -487,6 +487,7 @@ def gen_wcwidth() -> None: with create_header('kitty/wcwidth-std.h') as p: p('static int\nwcwidth_std(int32_t code) {') + p('\tif (LIKELY(0x20 <= code && code <= 0x7e)) return 1;') p('\tswitch(code) {') non_printing = class_maps['Cc'] | class_maps['Cf'] | class_maps['Cs'] diff --git a/kitty/wcwidth-std.h b/kitty/wcwidth-std.h index 43a74dc11..e2d379461 100644 --- a/kitty/wcwidth-std.h +++ b/kitty/wcwidth-std.h @@ -7,6 +7,7 @@ START_ALLOW_CASE_RANGE static int wcwidth_std(int32_t code) { + if (LIKELY(0x20 <= code && code <= 0x7e)) return 1; switch(code) { // Flags (26 codepoints) {{{ case 0x1f1e6 ... 0x1f1ff: