+2023-07-11 Bruno Haible <bruno@clisp.org>
+
+ Optimize away some mbsinit calls.
+ * lib/mbiter.h (mbiter_multi_next): When the module 'mbrtoc32-regular'
+ is in use, don't invoke mbsinit and don't compare the mbrtoc32 result
+ against (size_t)(-3).
+ * lib/mbuiter.h (mbuiter_multi_next): Likewise.
+ * lib/mbfile.h (mbfile_multi_getc): Likewise.
+ * lib/mbswidth.c (mbsnwidth): Likewise.
+ * lib/mbmemcasecoll.c (apply_c32tolower): Likewise.
+ * lib/quotearg.c (quotearg_buffer_restyled): Likewise.
+
2023-07-11 Bruno Haible <bruno@clisp.org>
Fix build errors on Linux/hppa.
/* If mbf->state is not in an initial state, some more 32-bit wide character
may be hiding in the state. We need to call mbrtoc32 again. */
+ #if GNULIB_MBRTOC32_REGULAR
+ assert (mbsinit (&mbf->state));
+ #else
if (mbsinit (&mbf->state))
+ #endif
{
/* Before using mbrtoc32, we need at least one byte. */
if (new_bufcount == 0)
assert (mbf->buf[0] == '\0');
assert (mbc->wc == 0);
}
+ #if !GNULIB_MBRTOC32_REGULAR
else if (bytes == (size_t) -3)
/* The previous multibyte sequence produced an additional 32-bit
wide character. */
bytes = 0;
+ #endif
mbc->wc_valid = true;
break;
}
assert (*iter->cur.ptr == '\0');
assert (iter->cur.wc == 0);
}
+ #if !GNULIB_MBRTOC32_REGULAR
else if (iter->cur.bytes == (size_t) -3)
/* The previous multibyte sequence produced an additional 32-bit
wide character. */
iter->cur.bytes = 0;
+ #endif
iter->cur.wc_valid = true;
/* When in an initial state, we can go back treating ASCII
characters more quickly. */
+ #if !GNULIB_MBRTOC32_REGULAR
if (mbsinit (&iter->state))
+ #endif
iter->in_shift = false;
}
}
mbstate_t state;
memset (&state, '\0', sizeof (mbstate_t));
- do
+ for (;;)
{
char32_t wc1;
size_t n1;
if (n1 == 0) /* NUL character? */
n1 = 1;
+ #if !GNULIB_MBRTOC32_REGULAR
else if (n1 == (size_t)(-3))
n1 = 0;
+ #endif
wc2 = c32tolower (wc1);
if (wc2 != wc1)
inbuf += n1;
remaining -= n1;
}
+ #if !GNULIB_MBRTOC32_REGULAR
+ if (mbsinit (&state))
+ #endif
+ break;
}
- while (! mbsinit (&state));
}
/* Verify the output buffer was large enough. */
{
mbstate_t mbstate;
memset (&mbstate, 0, sizeof mbstate);
- do
+ for (;;)
{
char32_t wc;
size_t bytes;
if (bytes == 0)
/* A null wide character was encountered. */
bytes = 1;
+ #if !GNULIB_MBRTOC32_REGULAR
else if (bytes == (size_t) -3)
bytes = 0;
+ #endif
w = c32width (wc);
if (w >= 0)
return -1;
p += bytes;
+ #if !GNULIB_MBRTOC32_REGULAR
+ if (mbsinit (&mbstate))
+ #endif
+ break;
}
- while (! mbsinit (&mbstate));
}
break;
}
assert (*iter->cur.ptr == '\0');
assert (iter->cur.wc == 0);
}
+ #if !GNULIB_MBRTOC32_REGULAR
else if (iter->cur.bytes == (size_t) -3)
/* The previous multibyte sequence produced an additional 32-bit
wide character. */
iter->cur.bytes = 0;
+ #endif
iter->cur.wc_valid = true;
/* When in an initial state, we can go back treating ASCII
characters more quickly. */
+ #if !GNULIB_MBRTOC32_REGULAR
if (mbsinit (&iter->state))
+ #endif
iter->in_shift = false;
}
}
if (argsize == SIZE_MAX)
argsize = strlen (arg);
- do
+ for (;;)
{
char32_t w;
size_t bytes = mbrtoc32 (&w, &arg[i + m],
}
else
{
+ #if !GNULIB_MBRTOC32_REGULAR
if (bytes == (size_t) -3)
bytes = 0;
+ #endif
/* Work around a bug with older shells that "see" a '\'
that is really the 2nd byte of a multibyte character.
In practice the problem is limited to ASCII
printable = false;
m += bytes;
}
+ #if !GNULIB_MBRTOC32_REGULAR
+ if (mbsinit (&mbstate))
+ #endif
+ break;
}
- while (! mbsinit (&mbstate));
}
c_and_shell_quote_compat = printable;