From: Bruno Haible <bruno@clisp.org>
Date: Sun, 16 Jul 2023 05:30:59 +0000 (+0200)
Subject: uchar-c23: Optimize clearing an mbstate_t.
X-Git-Tag: v1.0~1090
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=13cd6eb1e9f6d0a540727616ba6843648e74dc15;p=gnulib.git

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.
---

diff --git a/ChangeLog b/ChangeLog
index 7371228547..567c971b6f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-07-16  Bruno Haible  <bruno@clisp.org>
+
+	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  <bruno@clisp.org>
 
 	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