From 13cd6eb1e9f6d0a540727616ba6843648e74dc15 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 16 Jul 2023 07:30:59 +0200 Subject: [PATCH] uchar-c23: Optimize clearing an mbstate_t. * lib/lc-charset-unicode.c (locale_encoding_to_unicode, unicode_to_locale_encoding): Use mbszero. * modules/uchar-c23 (Depends-on): Add mbszero. --- ChangeLog | 7 +++++++ lib/lc-charset-unicode.c | 6 ++++-- modules/uchar-c23 | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7371228547..567c971b6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-07-16 Bruno Haible + + uchar-c23: Optimize clearing an mbstate_t. + * lib/lc-charset-unicode.c (locale_encoding_to_unicode, + unicode_to_locale_encoding): Use mbszero. + * modules/uchar-c23 (Depends-on): Add mbszero. + 2023-07-16 Bruno Haible quotearg: Optimize clearing an mbstate_t. diff --git a/lib/lc-charset-unicode.c b/lib/lc-charset-unicode.c index afbc188ad7..20994618b4 100644 --- a/lib/lc-charset-unicode.c +++ b/lib/lc-charset-unicode.c @@ -158,7 +158,8 @@ locale_encoding_to_unicode (wchar_t wc) char mbbuf[64]; size_t mbcnt; { - mbstate_t state = { 0 }; + mbstate_t state; + mbszero (&state); mbcnt = wcrtomb (mbbuf, wc, &state); if (mbcnt > sizeof (mbbuf)) /* wcrtomb did not recognize the wide character wc. */ @@ -248,7 +249,8 @@ unicode_to_locale_encoding (char32_t uc) wchar_t wc; { - mbstate_t state = { 0 }; + mbstate_t state; + mbszero (&state); if (mbrtowc (&wc, mbbuf, mbcnt, &state) != mbcnt) /* iconv produced an invalid multibyte sequence. */ return 0; diff --git a/modules/uchar-c23 b/modules/uchar-c23 index 11e08652cb..5fcd2802bf 100644 --- a/modules/uchar-c23 +++ b/modules/uchar-c23 @@ -13,6 +13,7 @@ localcharset streq lock tls +mbszero wcrtomb unistr/u8-mbtouc unistr/u8-uctomb -- 2.39.5