public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: convert sys_wcstombs/sys_mbstowcs wrapper to inline functions
@ 2020-07-10 8:30 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2020-07-10 8:30 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=462fcdb67f21c4806641c1cbbe0bc01a11d5ce44
commit 462fcdb67f21c4806641c1cbbe0bc01a11d5ce44
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Fri Jul 10 10:29:33 2020 +0200
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>
Diff:
---
winsup/cygwin/fhandler_console.cc | 2 +-
winsup/cygwin/nlsfuncs.cc | 4 +--
winsup/cygwin/strfuncs.cc | 60 ++++++++-----------------------------
winsup/cygwin/wchar.h | 62 +++++++++++++++++++++++++++++----------
4 files changed, 62 insertions(+), 66 deletions(-)
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index dd979fb8e..52741ce8b 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -403,7 +403,7 @@ dev_console::get_console_cp ()
inline DWORD
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
diff --git a/winsup/cygwin/nlsfuncs.cc b/winsup/cygwin/nlsfuncs.cc
index 0099a967f..668d7eb9e 100644
--- a/winsup/cygwin/nlsfuncs.cc
+++ b/winsup/cygwin/nlsfuncs.cc
@@ -1542,11 +1542,11 @@ internal_setlocale ()
if (path && *path) /* $PATH can be potentially unset. */
{
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 ();
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 ());
/* Set charset for internal conversion functions. */
cygheap->locale.mbtowc = __get_global_locale ()->mbtowc;
diff --git a/winsup/cygwin/strfuncs.cc b/winsup/cygwin/strfuncs.cc
index 604d7611c..07f2e48bb 100644
--- a/winsup/cygwin/strfuncs.cc
+++ b/winsup/cygwin/strfuncs.cc
@@ -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
function should be raised.
*/
-static size_t __reg3
-sys_wcstombs (char *dst, size_t len, const wchar_t *src, size_t nwc,
- bool is_path)
+size_t
+_sys_wcstombs (char *dst, size_t len, const wchar_t *src, size_t nwc,
+ bool is_path)
{
char buf[10];
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
ASCII area <= 0x7f (only for path names) is transform_chars above.
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
&& (((cwc = (pw & 0xff)) <= 0x7f && tfx_rev_chars[cwc] >= 0xf000)
|| (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;
}
-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
terminating '\0'. The buffer pointer is returned in *dst_p, the return
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
__small_vsprintf) and so when built there plain calloc is the
only choice. */
-static size_t __reg3
-sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src, size_t nwc,
+size_t
+_sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src, size_t nwc,
bool is_path)
{
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)
{
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));
if (!*dst_p)
return 0;
- ret = sys_wcstombs (*dst_p, dlen, src, nwc, is_path);
+ ret = _sys_wcstombs (*dst_p, dlen, src, nwc, is_path);
}
return ret;
}
-size_t __reg3
-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
+/* _sys_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
conversion. This is so that fhandler_console can switch to an alternate
charset, which is the charset returned by GetConsoleCP (). Most of the
time this is used for box and line drawing characters. */
-size_t __reg3
-sys_cp_mbstowcs (mbtowc_p f_mbtowc, wchar_t *dst, size_t dlen,
- const char *src, size_t nms)
+size_t
+_sys_mbstowcs (mbtowc_p f_mbtowc, wchar_t *dst, size_t dlen, const char *src,
+ size_t nms)
{
wchar_t *ptr = dst;
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;
}
-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. */
-size_t __reg3
+size_t
sys_mbstowcs_alloc (wchar_t **dst_p, int type, const char *src, size_t nms)
{
size_t ret;
diff --git a/winsup/cygwin/wchar.h b/winsup/cygwin/wchar.h
index b3dacf3b5..42919054a 100644
--- a/winsup/cygwin/wchar.h
+++ b/winsup/cygwin/wchar.h
@@ -45,22 +45,52 @@ extern wctomb_f __utf8_wctomb;
#ifdef __INSIDE_CYGWIN__
#ifdef __cplusplus
-size_t __reg3 sys_wcstombs (char *dst, size_t len, const wchar_t * src,
- size_t nwc = (size_t) -1);
-size_t __reg3 sys_wcstombs_no_path (char *dst, size_t len,
- const wchar_t * src,
- size_t nwc = (size_t) -1);
-size_t __reg3 sys_wcstombs_alloc (char **, int, const wchar_t *,
- size_t = (size_t) -1);
-size_t __reg3 sys_wcstombs_alloc_no_path (char **, int, const wchar_t *,
- 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);
+extern size_t _sys_wcstombs (char *dst, size_t len, const wchar_t *src,
+ size_t nwc, bool is_path);
+extern size_t _sys_wcstombs_alloc (char **dst_p, int type, const wchar_t *src,
+ size_t nwc, bool is_path);
+
+static inline size_t
+sys_wcstombs (char *dst, size_t len, const wchar_t * src,
+ size_t nwc = (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);
+
#endif /* __cplusplus */
#endif /* __INSIDE_CYGWIN__ */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-07-10 8:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-10 8:30 [newlib-cygwin] Cygwin: convert sys_wcstombs/sys_mbstowcs wrapper to inline functions Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).