From: Steve Bennett Date: Sun, 4 Sep 2016 03:09:25 +0000 (+1000) Subject: Add a fast path for utf8_width() X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=66676c7030ce2e71f90713290cb39459f78d61d9;p=linenoise.git Add a fast path for utf8_width() For common ASCII characters Signed-off-by: Steve Bennett --- diff --git a/utf8.c b/utf8.c index 966ca85..0edf450 100644 --- a/utf8.c +++ b/utf8.c @@ -212,6 +212,10 @@ static int utf8_in_range(const struct utf8range *range, int num, int ch) int utf8_width(int ch) { + /* short circuit for common case */ + if (isascii(ch)) { + return 1; + } if (utf8_in_range(unicode_range_combining, ARRAYSIZE(unicode_range_combining), ch)) { return 0; }