]> git.lizzy.rs Git - linenoise.git/commitdiff
Add a fast path for utf8_width()
authorSteve Bennett <steveb@workware.net.au>
Sun, 4 Sep 2016 03:09:25 +0000 (13:09 +1000)
committerSteve Bennett <steveb@workware.net.au>
Sun, 4 Sep 2016 03:09:25 +0000 (13:09 +1000)
For common ASCII characters

Signed-off-by: Steve Bennett <steveb@workware.net.au>
utf8.c

diff --git a/utf8.c b/utf8.c
index 966ca854847efc30887f9887f42602e8a01ac630..0edf450b09529a1cf5880d4057fab8e881489c20 100644 (file)
--- 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;
     }