From: Natanael Copa <ncopa@alpinelinux.org>
To: musl@lists.openwall.com
Cc: Natanael Copa <ncopa@alpinelinux.org>
Subject: [PATCH] towupper/towlower: fast path for ascii chars
Date: Tue, 30 May 2017 14:23:24 +0200 [thread overview]
Message-ID: <20170530122324.23733-1-ncopa@alpinelinux.org> (raw)
In-Reply-To: <20170527005950.GA1627@brightrain.aerifal.cx>
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 <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)
--
2.13.0
next prev parent reply other threads:[~2017-05-30 12:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-25 18:01 towlower performance maksis .
2017-05-27 0:39 ` Andre McCurdy
2017-05-27 0:59 ` Rich Felker
2017-05-30 12:23 ` Natanael Copa [this message]
2017-05-31 3:04 ` [PATCH] towupper/towlower: fast path for ascii chars A. Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170530122324.23733-1-ncopa@alpinelinux.org \
--to=ncopa@alpinelinux.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).