* lib/mbslen.c: Include mbuiterf.h instead of mbuiter.h.
(mbslen): Use mbuif_* macros instead of mbui_* macros.
* modules/mbslen (Depends-on): Add mbuiterf. Remove mbuiter.
2023-07-18 Bruno Haible <bruno@clisp.org>
+ mbslen: Optimize.
+ * lib/mbslen.c: Include mbuiterf.h instead of mbuiter.h.
+ (mbslen): Use mbuif_* macros instead of mbui_* macros.
+ * modules/mbslen (Depends-on): Add mbuiterf. Remove mbuiter.
+
mbuiterf: Add a benchmark.
* tests/bench-mbuiterf.c: New file, based on tests/bench-mbuiter.c.
* modules/mbuiterf-bench-tests: New file, based on
#include <stdlib.h>
-#include "mbuiter.h"
+#include "mbuiterf.h"
/* Return the number of multibyte characters in the character string STRING. */
size_t
{
if (MB_CUR_MAX > 1)
{
- size_t count;
- mbui_iterator_t iter;
-
- count = 0;
- for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter))
- count++;
+ size_t count = 0;
+
+ mbuif_state_t state;
+ const char *iter;
+ for (mbuif_init (state), iter = string; mbuif_avail (state, iter); )
+ {
+ mbchar_t cur = mbuif_next (state, iter);
+ count++;
+ iter += mb_len (cur);
+ }
return count;
}
m4/mbslen.m4
Depends-on:
-mbuiter
+mbuiterf
string
configure.ac: