From 4159dd5027ee68631e3514aa31f614a5b0d08303 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 16 Jul 2023 07:30:20 +0200 Subject: [PATCH] mbtowc: Optimize clearing an mbstate_t. * lib/mbtowc-impl.h (mbtowc): Use mbszero. * modules/mbtowc (Depends-on): Add mbszero. --- ChangeLog | 6 ++++++ lib/mbtowc-impl.h | 2 +- modules/mbtowc | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 151d9b4537..e32eaf8ad4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-07-16 Bruno Haible + + mbtowc: Optimize clearing an mbstate_t. + * lib/mbtowc-impl.h (mbtowc): Use mbszero. + * modules/mbtowc (Depends-on): Add mbszero. + 2023-07-16 Bruno Haible mbszero: New module. diff --git a/lib/mbtowc-impl.h b/lib/mbtowc-impl.h index 39b977bebc..01fef1823d 100644 --- a/lib/mbtowc-impl.h +++ b/lib/mbtowc-impl.h @@ -30,7 +30,7 @@ mbtowc (wchar_t *pwc, const char *s, size_t n) wchar_t wc; size_t result; - memset (&state, 0, sizeof (mbstate_t)); + mbszero (&state); result = mbrtowc (&wc, s, n, &state); if (result == (size_t)-1 || result == (size_t)-2) { diff --git a/modules/mbtowc b/modules/mbtowc index fcfb1cc431..12cc3de62d 100644 --- a/modules/mbtowc +++ b/modules/mbtowc @@ -8,8 +8,9 @@ m4/mbtowc.m4 Depends-on: stdlib -mbrtowc [test $HAVE_MBTOWC = 0 || test $REPLACE_MBTOWC = 1] wchar [test $HAVE_MBTOWC = 0 || test $REPLACE_MBTOWC = 1] +mbszero [test $HAVE_MBTOWC = 0 || test $REPLACE_MBTOWC = 1] +mbrtowc [test $HAVE_MBTOWC = 0 || test $REPLACE_MBTOWC = 1] configure.ac: gl_FUNC_MBTOWC -- 2.39.5