mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-18 23:12:15 +08:00
Cygwin: convert sys_wcstombs/sys_mbstowcs wrapper to inline functions
This should slightly speed up especially path conversions, given there's one less function call rearranging all function arguments in registers/stack (and less stack pressure). For clarity, rename overloaded sys_wcstombs to _sys_wcstombs and sys_cp_mbstowcs to _sys_mbstowcs. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
f007b6e24a
commit
dfa37a4b42
@ -403,7 +403,7 @@ dev_console::get_console_cp ()
|
|||||||
inline DWORD
|
inline DWORD
|
||||||
dev_console::str_to_con (mbtowc_p f_mbtowc, PWCHAR d, const char *s, DWORD sz)
|
dev_console::str_to_con (mbtowc_p f_mbtowc, PWCHAR d, const char *s, DWORD sz)
|
||||||
{
|
{
|
||||||
return sys_cp_mbstowcs (f_mbtowc, d, CONVERT_LIMIT, s, sz);
|
return _sys_mbstowcs (f_mbtowc, d, CONVERT_LIMIT, s, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -1542,11 +1542,11 @@ internal_setlocale ()
|
|||||||
if (path && *path) /* $PATH can be potentially unset. */
|
if (path && *path) /* $PATH can be potentially unset. */
|
||||||
{
|
{
|
||||||
w_path = tp.w_get ();
|
w_path = tp.w_get ();
|
||||||
sys_cp_mbstowcs (cygheap->locale.mbtowc, w_path, 32768, path);
|
_sys_mbstowcs (cygheap->locale.mbtowc, w_path, 32768, path);
|
||||||
}
|
}
|
||||||
w_cwd = tp.w_get ();
|
w_cwd = tp.w_get ();
|
||||||
cwdstuff::cwd_lock.acquire ();
|
cwdstuff::cwd_lock.acquire ();
|
||||||
sys_cp_mbstowcs (cygheap->locale.mbtowc, w_cwd, 32768,
|
_sys_mbstowcs (cygheap->locale.mbtowc, w_cwd, 32768,
|
||||||
cygheap->cwd.get_posix ());
|
cygheap->cwd.get_posix ());
|
||||||
/* Set charset for internal conversion functions. */
|
/* Set charset for internal conversion functions. */
|
||||||
cygheap->locale.mbtowc = __get_global_locale ()->mbtowc;
|
cygheap->locale.mbtowc = __get_global_locale ()->mbtowc;
|
||||||
|
@ -410,9 +410,9 @@ __big5_mbtowc (struct _reent *r, wchar_t *pwc, const char *s, size_t n,
|
|||||||
to buffer size, it's a bug in Cygwin and the buffer in the calling
|
to buffer size, it's a bug in Cygwin and the buffer in the calling
|
||||||
function should be raised.
|
function should be raised.
|
||||||
*/
|
*/
|
||||||
static size_t __reg3
|
size_t
|
||||||
sys_wcstombs (char *dst, size_t len, const wchar_t *src, size_t nwc,
|
_sys_wcstombs (char *dst, size_t len, const wchar_t *src, size_t nwc,
|
||||||
bool is_path)
|
bool is_path)
|
||||||
{
|
{
|
||||||
char buf[10];
|
char buf[10];
|
||||||
char *ptr = dst;
|
char *ptr = dst;
|
||||||
@ -436,7 +436,7 @@ sys_wcstombs (char *dst, size_t len, const wchar_t *src, size_t nwc,
|
|||||||
/* Convert UNICODE private use area. Reverse functionality for the
|
/* Convert UNICODE private use area. Reverse functionality for the
|
||||||
ASCII area <= 0x7f (only for path names) is transform_chars above.
|
ASCII area <= 0x7f (only for path names) is transform_chars above.
|
||||||
Reverse functionality for invalid bytes in a multibyte sequence is
|
Reverse functionality for invalid bytes in a multibyte sequence is
|
||||||
in sys_cp_mbstowcs below. */
|
in _sys_mbstowcs below. */
|
||||||
if (is_path && (pw & 0xff00) == 0xf000
|
if (is_path && (pw & 0xff00) == 0xf000
|
||||||
&& (((cwc = (pw & 0xff)) <= 0x7f && tfx_rev_chars[cwc] >= 0xf000)
|
&& (((cwc = (pw & 0xff)) <= 0x7f && tfx_rev_chars[cwc] >= 0xf000)
|
||||||
|| (cwc >= 0x80 && MB_CUR_MAX > 1)))
|
|| (cwc >= 0x80 && MB_CUR_MAX > 1)))
|
||||||
@ -498,18 +498,6 @@ sys_wcstombs (char *dst, size_t len, const wchar_t *src, size_t nwc,
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t __reg3
|
|
||||||
sys_wcstombs (char *dst, size_t len, const wchar_t * src, size_t nwc)
|
|
||||||
{
|
|
||||||
return sys_wcstombs (dst, len, src, nwc, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t __reg3
|
|
||||||
sys_wcstombs_no_path (char *dst, size_t len, const wchar_t * src, size_t nwc)
|
|
||||||
{
|
|
||||||
return sys_wcstombs (dst, len, src, nwc, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate a buffer big enough for the string, always including the
|
/* Allocate a buffer big enough for the string, always including the
|
||||||
terminating '\0'. The buffer pointer is returned in *dst_p, the return
|
terminating '\0'. The buffer pointer is returned in *dst_p, the return
|
||||||
value is the number of bytes written to the buffer, as usual.
|
value is the number of bytes written to the buffer, as usual.
|
||||||
@ -520,13 +508,13 @@ sys_wcstombs_no_path (char *dst, size_t len, const wchar_t * src, size_t nwc)
|
|||||||
Note that this code is shared by cygserver (which requires it via
|
Note that this code is shared by cygserver (which requires it via
|
||||||
__small_vsprintf) and so when built there plain calloc is the
|
__small_vsprintf) and so when built there plain calloc is the
|
||||||
only choice. */
|
only choice. */
|
||||||
static size_t __reg3
|
size_t
|
||||||
sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src, size_t nwc,
|
_sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src, size_t nwc,
|
||||||
bool is_path)
|
bool is_path)
|
||||||
{
|
{
|
||||||
size_t ret;
|
size_t ret;
|
||||||
|
|
||||||
ret = sys_wcstombs (NULL, (size_t) -1, src, nwc, is_path);
|
ret = _sys_wcstombs (NULL, (size_t) -1, src, nwc, is_path);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
size_t dlen = ret + 1;
|
size_t dlen = ret + 1;
|
||||||
@ -537,32 +525,19 @@ sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src, size_t nwc,
|
|||||||
*dst_p = (char *) ccalloc ((cygheap_types) type, dlen, sizeof (char));
|
*dst_p = (char *) ccalloc ((cygheap_types) type, dlen, sizeof (char));
|
||||||
if (!*dst_p)
|
if (!*dst_p)
|
||||||
return 0;
|
return 0;
|
||||||
ret = sys_wcstombs (*dst_p, dlen, src, nwc, is_path);
|
ret = _sys_wcstombs (*dst_p, dlen, src, nwc, is_path);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t __reg3
|
/* _sys_mbstowcs is actually most of the time called as sys_mbstowcs with
|
||||||
sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src, size_t nwc)
|
|
||||||
{
|
|
||||||
return sys_wcstombs_alloc (dst_p, type, src, nwc, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t __reg3
|
|
||||||
sys_wcstombs_alloc_no_path (char **dst_p, int type, const wchar_t *src,
|
|
||||||
size_t nwc)
|
|
||||||
{
|
|
||||||
return sys_wcstombs_alloc (dst_p, type, src, nwc, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* sys_cp_mbstowcs is actually most of the time called as sys_mbstowcs with
|
|
||||||
a 0 codepage. If cp is not 0, the codepage is evaluated and used for the
|
a 0 codepage. If cp is not 0, the codepage is evaluated and used for the
|
||||||
conversion. This is so that fhandler_console can switch to an alternate
|
conversion. This is so that fhandler_console can switch to an alternate
|
||||||
charset, which is the charset returned by GetConsoleCP (). Most of the
|
charset, which is the charset returned by GetConsoleCP (). Most of the
|
||||||
time this is used for box and line drawing characters. */
|
time this is used for box and line drawing characters. */
|
||||||
size_t __reg3
|
size_t
|
||||||
sys_cp_mbstowcs (mbtowc_p f_mbtowc, wchar_t *dst, size_t dlen,
|
_sys_mbstowcs (mbtowc_p f_mbtowc, wchar_t *dst, size_t dlen, const char *src,
|
||||||
const char *src, size_t nms)
|
size_t nms)
|
||||||
{
|
{
|
||||||
wchar_t *ptr = dst;
|
wchar_t *ptr = dst;
|
||||||
unsigned const char *pmbs = (unsigned const char *) src;
|
unsigned const char *pmbs = (unsigned const char *) src;
|
||||||
@ -670,17 +645,8 @@ sys_cp_mbstowcs (mbtowc_p f_mbtowc, wchar_t *dst, size_t dlen,
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t __reg3
|
|
||||||
sys_mbstowcs (wchar_t * dst, size_t dlen, const char *src, size_t nms)
|
|
||||||
{
|
|
||||||
mbtowc_p f_mbtowc = __MBTOWC;
|
|
||||||
if (f_mbtowc == __ascii_mbtowc)
|
|
||||||
f_mbtowc = __utf8_mbtowc;
|
|
||||||
return sys_cp_mbstowcs (f_mbtowc, dst, dlen, src, nms);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Same as sys_wcstombs_alloc, just backwards. */
|
/* Same as sys_wcstombs_alloc, just backwards. */
|
||||||
size_t __reg3
|
size_t
|
||||||
sys_mbstowcs_alloc (wchar_t **dst_p, int type, const char *src, size_t nms)
|
sys_mbstowcs_alloc (wchar_t **dst_p, int type, const char *src, size_t nms)
|
||||||
{
|
{
|
||||||
size_t ret;
|
size_t ret;
|
||||||
|
@ -45,22 +45,52 @@ extern wctomb_f __utf8_wctomb;
|
|||||||
|
|
||||||
#ifdef __INSIDE_CYGWIN__
|
#ifdef __INSIDE_CYGWIN__
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
size_t __reg3 sys_wcstombs (char *dst, size_t len, const wchar_t * src,
|
extern size_t _sys_wcstombs (char *dst, size_t len, const wchar_t *src,
|
||||||
size_t nwc = (size_t) -1);
|
size_t nwc, bool is_path);
|
||||||
size_t __reg3 sys_wcstombs_no_path (char *dst, size_t len,
|
extern size_t _sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src,
|
||||||
const wchar_t * src,
|
size_t nwc, bool is_path);
|
||||||
size_t nwc = (size_t) -1);
|
|
||||||
size_t __reg3 sys_wcstombs_alloc (char **, int, const wchar_t *,
|
static inline size_t
|
||||||
size_t = (size_t) -1);
|
sys_wcstombs (char *dst, size_t len, const wchar_t * src,
|
||||||
size_t __reg3 sys_wcstombs_alloc_no_path (char **, int, const wchar_t *,
|
size_t nwc = (size_t) -1)
|
||||||
size_t = (size_t) -1);
|
{
|
||||||
|
return _sys_wcstombs (dst, len, src, nwc, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline size_t
|
||||||
|
sys_wcstombs_no_path (char *dst, size_t len, const wchar_t * src,
|
||||||
|
size_t nwc = (size_t) -1)
|
||||||
|
{
|
||||||
|
return _sys_wcstombs (dst, len, src, nwc, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline size_t
|
||||||
|
sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src,
|
||||||
|
size_t nwc = (size_t) -1)
|
||||||
|
{
|
||||||
|
return _sys_wcstombs_alloc (dst_p, type, src, nwc, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline size_t
|
||||||
|
sys_wcstombs_alloc_no_path (char **dst_p, int type, const wchar_t *src,
|
||||||
|
size_t nwc = (size_t) -1)
|
||||||
|
{
|
||||||
|
return _sys_wcstombs_alloc (dst_p, type, src, nwc, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t _sys_mbstowcs (mbtowc_p, wchar_t *, size_t, const char *,
|
||||||
|
size_t = (size_t) -1);
|
||||||
|
|
||||||
|
static inline size_t
|
||||||
|
sys_mbstowcs (wchar_t * dst, size_t dlen, const char *src,
|
||||||
|
size_t nms = (size_t) -1)
|
||||||
|
{
|
||||||
|
mbtowc_p f_mbtowc = (__MBTOWC == __ascii_mbtowc) ? __utf8_mbtowc : __MBTOWC;
|
||||||
|
return _sys_mbstowcs (f_mbtowc, dst, dlen, src, nms);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t sys_mbstowcs_alloc (wchar_t **, int, const char *, size_t = (size_t) -1);
|
||||||
|
|
||||||
size_t __reg3 sys_cp_mbstowcs (mbtowc_p, wchar_t *, size_t, const char *,
|
|
||||||
size_t = (size_t) -1);
|
|
||||||
size_t __reg3 sys_mbstowcs (wchar_t * dst, size_t dlen, const char *src,
|
|
||||||
size_t nms = (size_t) -1);
|
|
||||||
size_t __reg3 sys_mbstowcs_alloc (wchar_t **, int, const char *,
|
|
||||||
size_t = (size_t) -1);
|
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
#endif /* __INSIDE_CYGWIN__ */
|
#endif /* __INSIDE_CYGWIN__ */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user