towupper/towlower: fast path for ascii chars
authorNatanael Copa <ncopa@alpinelinux.org>
Tue, 30 May 2017 12:23:24 +0000 (14:23 +0200)
committerRich Felker <dalias@aerifal.cx>
Thu, 1 Jun 2017 01:54:22 +0000 (21:54 -0400)
Make a fast path for ascii chars which is assumed to be the most common
case. This has significant performance benefit on xml json and similar

src/ctype/towctrans.c

index 6af6187..cf13a86 100644 (file)
@@ -1,3 +1,4 @@
+#include <ctype.h>
 #include <wctype.h>
 #include "libc.h"
 
@@ -9,7 +10,6 @@ static const struct {
        signed char lower;
        unsigned char len;
 } casemaps[] = {
-       CASEMAP('A','Z','a'),
        CASEMAP(0xc0,0xde,0xe0),
 
        CASELACE(0x0100,0x012e),
@@ -257,12 +257,12 @@ static wchar_t __towcase(wchar_t wc, int lower)
 
 wint_t towupper(wint_t wc)
 {
-       return __towcase(wc, 0);
+       return (unsigned)wc < 128 ? toupper(wc) : __towcase(wc, 0);
 }
 
 wint_t towlower(wint_t wc)
 {
-       return __towcase(wc, 1);
+       return (unsigned)wc < 128 ? tolower(wc) : __towcase(wc, 1);
 }
 
 wint_t __towupper_l(wint_t c, locale_t l)