Reduce overhead by calling internal versions of the multibyte conversion

functions directly wherever possible.
This commit is contained in:
Tim J. Robbins 2004-05-12 14:26:54 +00:00
parent 2051a8f2d5
commit 6155c34adf
8 changed files with 19 additions and 11 deletions

View File

@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <wchar.h>
#include "mblocal.h"
wint_t
btowc(int c)
@ -46,7 +47,7 @@ btowc(int c)
* counts.
*/
cc = (char)c;
if (mbrtowc(&wc, &cc, 1, &mbs) > 1)
if (__mbrtowc(&wc, &cc, 1, &mbs) > 1)
return (WEOF);
return (wc);
}

View File

@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$");
#include <limits.h>
#include <stdlib.h>
#include <wchar.h>
#include "mblocal.h"
int
mblen(const char *s, size_t n)
@ -44,7 +45,7 @@ mblen(const char *s, size_t n)
mbs = initial;
return (0);
}
rval = mbrtowc(NULL, s, n, &mbs);
rval = __mbrtowc(NULL, s, n, &mbs);
if (rval == (size_t)-1 || rval == (size_t)-2)
return (-1);
if (rval > INT_MAX) {

View File

@ -28,6 +28,7 @@
__FBSDID("$FreeBSD$");
#include <wchar.h>
#include "mblocal.h"
size_t
mbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps)
@ -36,5 +37,5 @@ mbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps)
if (ps == NULL)
ps = &mbs;
return (mbrtowc(NULL, s, n, ps));
return (__mbrtowc(NULL, s, n, ps));
}

View File

@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$");
#include <limits.h>
#include <stdlib.h>
#include <wchar.h>
#include "mblocal.h"
size_t
mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len,
@ -49,7 +50,7 @@ mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len,
ps = &mbs;
if (dst == NULL) {
for (;;) {
if ((nb = (int)mbrtowc(&wc, s, MB_CUR_MAX, ps)) < 0)
if ((nb = (int)__mbrtowc(&wc, s, MB_CUR_MAX, ps)) < 0)
/* Invalid sequence - mbrtowc() sets errno. */
return ((size_t)-1);
else if (nb == 0)
@ -61,7 +62,7 @@ mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len,
}
while (len-- > 0) {
if ((nb = (int)mbrtowc(dst, s, MB_CUR_MAX, ps)) < 0) {
if ((nb = (int)__mbrtowc(dst, s, MB_CUR_MAX, ps)) < 0) {
*src = s;
return ((size_t)-1);
} else if (nb == 0) {

View File

@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include "mblocal.h"
int
mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n)
@ -45,7 +46,7 @@ mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n)
mbs = initial;
return (0);
}
rval = mbrtowc(pwc, s, n, &mbs);
rval = __mbrtowc(pwc, s, n, &mbs);
if (rval == (size_t)-1 || rval == (size_t)-2)
return (-1);
if (rval > INT_MAX) {

View File

@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include "mblocal.h"
size_t
wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len,
@ -50,7 +51,7 @@ wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len,
ps = &mbs;
if (dst == NULL) {
for (;;) {
if ((nb = (int)wcrtomb(buf, *s, ps)) < 0)
if ((nb = (int)__wcrtomb(buf, *s, ps)) < 0)
/* Invalid character - wcrtomb() sets errno. */
return ((size_t)-1);
else if (*s == L'\0')
@ -64,7 +65,7 @@ wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len,
while (len > 0) {
if (len > (size_t)MB_CUR_MAX) {
/* Enough space to translate in-place. */
if ((nb = (int)wcrtomb(dst, *s, ps)) < 0) {
if ((nb = (int)__wcrtomb(dst, *s, ps)) < 0) {
*src = s;
return ((size_t)-1);
}
@ -77,7 +78,7 @@ wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len,
* character is too long for the buffer.
*/
mbsbak = *ps;
if ((nb = (int)wcrtomb(buf, *s, ps)) < 0) {
if ((nb = (int)__wcrtomb(buf, *s, ps)) < 0) {
*src = s;
return ((size_t)-1);
}

View File

@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
#include <limits.h>
#include <stdio.h>
#include <wchar.h>
#include "mblocal.h"
int
wctob(wint_t c)
@ -38,7 +39,7 @@ wctob(wint_t c)
mbstate_t mbs = initial;
char buf[MB_LEN_MAX];
if (c == WEOF || wcrtomb(buf, c, &mbs) != 1)
if (c == WEOF || __wcrtomb(buf, c, &mbs) != 1)
return (EOF);
return ((unsigned char)*buf);
}

View File

@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include "mblocal.h"
int
wctomb(char *s, wchar_t wchar)
@ -45,7 +46,7 @@ wctomb(char *s, wchar_t wchar)
mbs = initial;
return (0);
}
if ((rval = wcrtomb(s, wchar, &mbs)) == (size_t)-1)
if ((rval = __wcrtomb(s, wchar, &mbs)) == (size_t)-1)
return (-1);
if (rval > INT_MAX) {
errno = ERANGE;