]> Savannah Git Hosting - gnulib.git/commitdiff
mbslen: Optimize.
authorBruno Haible <bruno@clisp.org>
Tue, 18 Jul 2023 11:27:44 +0000 (13:27 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 18 Jul 2023 11:27:44 +0000 (13:27 +0200)
* 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.

ChangeLog
lib/mbslen.c
modules/mbslen

index 6380a3cbc06077c7ffe0fdec0fc3782d961a08bc..d1b135958c73e42d5a00bac9c19b6b6e6a681282 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 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
index 54c20be02f0b1d90c949c7f82ecfdb29512137b0..18642f55e96096efe206cf90c6affb349bf3d7d2 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <stdlib.h>
 
-#include "mbuiter.h"
+#include "mbuiterf.h"
 
 /* Return the number of multibyte characters in the character string STRING.  */
 size_t
@@ -30,12 +30,16 @@ mbslen (const char *string)
 {
   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;
     }
index 55993aa59c763ad85429d1a4a53b9888ea8b1430..6b6c6078e5afc25ea724f7ee0dc7e00fe2f7df4a 100644 (file)
@@ -6,7 +6,7 @@ lib/mbslen.c
 m4/mbslen.m4
 
 Depends-on:
-mbuiter
+mbuiterf
 string
 
 configure.ac: