From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11374 Path: news.gmane.org!.POSTED!not-for-mail From: Natanael Copa Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] towupper/towlower: fast path for ascii chars Date: Tue, 30 May 2017 14:23:24 +0200 Message-ID: <20170530122324.23733-1-ncopa@alpinelinux.org> References: <20170527005950.GA1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1496147039 21348 195.159.176.226 (30 May 2017 12:23:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 30 May 2017 12:23:59 +0000 (UTC) Cc: Natanael Copa To: musl@lists.openwall.com Original-X-From: musl-return-11387-gllmg-musl=m.gmane.org@lists.openwall.com Tue May 30 14:23:55 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dFgBm-0005UZ-M5 for gllmg-musl@m.gmane.org; Tue, 30 May 2017 14:23:54 +0200 Original-Received: (qmail 12147 invoked by uid 550); 30 May 2017 12:23:57 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 12115 invoked from network); 30 May 2017 12:23:55 -0000 X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170527005950.GA1627@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:11374 Archived-At: 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 --- This gives a performance boost for the given testcase: https://gist.github.com/maksis/92ad04f525d69043283350675d04f160 Before: Completed in 8.302969s, compare count 54136421 After: Completed in 2.745886s, compare count 54136421 I don't consider this the final solution but it is atleast a significant improvement. src/ctype/towctrans.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ctype/towctrans.c b/src/ctype/towctrans.c index 6af61875..cf13a862 100644 --- a/src/ctype/towctrans.c +++ b/src/ctype/towctrans.c @@ -1,3 +1,4 @@ +#include #include #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) -- 2.13.0