summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2004-07-09 15:46:06 +0000
committertjr <tjr@FreeBSD.org>2004-07-09 15:46:06 +0000
commit0bea5c010822d29aa9e614f86ee4e71cac7876cb (patch)
treef70a23afb81a2bb69ccea6c4349f9dd0727d3d76 /lib
parente224905046c4623318e94424834fcfbc63f106bd (diff)
downloadFreeBSD-src-0bea5c010822d29aa9e614f86ee4e71cac7876cb.zip
FreeBSD-src-0bea5c010822d29aa9e614f86ee4e71cac7876cb.tar.gz
Add fast paths for conversion of plain ASCII characters.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/locale/utf8.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/libc/locale/utf8.c b/lib/libc/locale/utf8.c
index c0fbcf4..bab04f0 100644
--- a/lib/libc/locale/utf8.c
+++ b/lib/libc/locale/utf8.c
@@ -90,6 +90,13 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
/* Incomplete multibyte sequence */
return ((size_t)-2);
+ if (us->want == 0 && ((ch = (unsigned char)*s) & ~0x7f) == 0) {
+ /* Fast path for plain ASCII characters. */
+ if (pwc != NULL)
+ *pwc = ch;
+ return (ch != '\0' ? 1 : 0);
+ }
+
if (us->want == 0) {
/*
* Determine the number of octets that make up this character
@@ -198,6 +205,12 @@ _UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
/* Reset to initial shift state (no-op) */
return (1);
+ if ((wc & ~0x7f) == 0) {
+ /* Fast path for plain ASCII characters. */
+ *s = (char)wc;
+ return (1);
+ }
+
/*
* Determine the number of octets needed to represent this character.
* We always output the shortest sequence possible. Also specify the
OpenPOWER on IntegriCloud