Add fast paths for conversion of plain ASCII characters.

This commit is contained in:
Tim J. Robbins 2004-07-09 15:46:06 +00:00
parent fcc5191787
commit 550473de5b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=131881

View file

@ -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