summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2014-07-04 22:39:39 +0000
committerpfg <pfg@FreeBSD.org>2014-07-04 22:39:39 +0000
commit005e0d33a793f8d36accd1174e8cd61eb0b6ebb1 (patch)
tree2b3a8712f331ca187b132209487a0c113119ab96
parent6e29f84795d4884ec6d9cfe50f45177baa99f7df (diff)
downloadFreeBSD-src-005e0d33a793f8d36accd1174e8cd61eb0b6ebb1.zip
FreeBSD-src-005e0d33a793f8d36accd1174e8cd61eb0b6ebb1.tar.gz
minor perf enhancement for UTF-8
Reduce some duplicate code. Reference: https://www.illumos.org/issues/628 Obtained from: Illumos MFC after: 1 week
-rw-r--r--lib/libc/locale/utf8.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/lib/libc/locale/utf8.c b/lib/libc/locale/utf8.c
index cffa241..ce49279 100644
--- a/lib/libc/locale/utf8.c
+++ b/lib/libc/locale/utf8.c
@@ -1,4 +1,5 @@
/*-
+ * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2002-2004 Tim J. Robbins
* All rights reserved.
*
@@ -112,13 +113,6 @@ _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
@@ -134,10 +128,12 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
*/
ch = (unsigned char)*s;
if ((ch & 0x80) == 0) {
- mask = 0x7f;
- want = 1;
- lbound = 0;
- } else if ((ch & 0xe0) == 0xc0) {
+ /* Fast path for plain ASCII characters. */
+ if (pwc != NULL)
+ *pwc = ch;
+ return (ch != '\0' ? 1 : 0);
+ }
+ if ((ch & 0xe0) == 0xc0) {
mask = 0x1f;
want = 2;
lbound = 0x80;
@@ -316,12 +312,6 @@ _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
@@ -329,8 +319,9 @@ _UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
* about the sequence length.
*/
if ((wc & ~0x7f) == 0) {
- lead = 0;
- len = 1;
+ /* Fast path for plain ASCII characters. */
+ *s = (char)wc;
+ return (1);
} else if ((wc & ~0x7ff) == 0) {
lead = 0xc0;
len = 2;
OpenPOWER on IntegriCloud