* lib/mbsnlen.c: Include mbiterf.h instead of mbiter.h.
(mbsnlen): Use mbif_* macros instead of mbi_* macros.
* modules/mbsnlen (Depends-on): Add mbiterf. Remove mbiter.
2023-07-18 Bruno Haible <bruno@clisp.org>
+ mbsnlen: Optimize.
+ * lib/mbsnlen.c: Include mbiterf.h instead of mbiter.h.
+ (mbsnlen): Use mbif_* macros instead of mbi_* macros.
+ * modules/mbsnlen (Depends-on): Add mbiterf. Remove mbiter.
+
mbiterf: Add a benchmark.
* tests/bench-mbiterf.c: New file, based on tests/bench-mbiter.c.
* modules/mbiterf-bench-tests: New file, based on
#include <stdlib.h>
-#include "mbiter.h"
+#include "mbiterf.h"
/* Return the number of multibyte characters in the character string starting
at STRING and ending at STRING + LEN. */
{
if (MB_CUR_MAX > 1)
{
- size_t count;
- mbi_iterator_t iter;
-
- count = 0;
- for (mbi_init (iter, string, len); mbi_avail (iter); mbi_advance (iter))
- count++;
+ size_t count = 0;
+
+ const char *string_end = string + len;
+ mbif_state_t state;
+ const char *iter;
+ for (mbif_init (state), iter = string; mbif_avail (state, iter, string_end); )
+ {
+ mbchar_t cur = mbif_next (state, iter, string_end);
+ count++;
+ iter += mb_len (cur);
+ }
return count;
}
lib/mbsnlen.c
Depends-on:
-mbiter
+mbiterf
string
configure.ac: