From 7219d38b5716cd25af2eb177c03948b9908e09c6 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 7 Sep 2023 14:51:58 -0700 Subject: [PATCH] exclude: support GNULIB_MCEL_PREFER Support mcel API for apps that prefer it. The following changes are in effect only if GNULIB_MCEL_PREFER. * lib/exclude.c: Include mcel.h instead of mbuiter.h. (string_hasher_ci): Use mcel_scanz instead of mbui_init, mbui_avail, mbui_cur, and mbui_advance. * modules/exclude: Do not depend on mbuiter. --- ChangeLog | 8 ++++++++ lib/exclude.c | 16 +++++++++++++++- modules/exclude | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c967214ed..ba49a1177b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2023-09-07 Paul Eggert + exclude: support GNULIB_MCEL_PREFER + Support mcel API for apps that prefer it. + The following changes are in effect only if GNULIB_MCEL_PREFER. + * lib/exclude.c: Include mcel.h instead of mbuiter.h. + (string_hasher_ci): Use mcel_scanz instead of mbui_init, + mbui_avail, mbui_cur, and mbui_advance. + * modules/exclude: Do not depend on mbuiter. + mcel-prefer: new module * modules/mcel-prefer: New file. diff --git a/lib/exclude.c b/lib/exclude.c index d1ecaedfc6..a3479db8a6 100644 --- a/lib/exclude.c +++ b/lib/exclude.c @@ -36,7 +36,11 @@ #include "filename.h" #include "fnmatch.h" #include "hash.h" -#include "mbuiter.h" +#if GNULIB_MCEL_PREFER +# include "mcel.h" +#else +# include "mbuiter.h" +#endif #include "xalloc.h" #if GNULIB_EXCLUDE_SINGLE_THREAD @@ -204,7 +208,16 @@ string_hasher_ci (void const *data, size_t n_buckets) char const *p = data; size_t value = 0; +#if GNULIB_MCEL_PREFER + while (*p) + { + mcel_t g = mcel_scanz (p); + value = value * 31 + (c32tolower (g.ch) - g.err); + p += g.len; + } +#else mbui_iterator_t iter; + for (mbui_init (iter, p); mbui_avail (iter); mbui_advance (iter)) { mbchar_t m = mbui_cur (iter); @@ -217,6 +230,7 @@ string_hasher_ci (void const *data, size_t n_buckets) value = value * 31 + wc; } +#endif return value % n_buckets; } diff --git a/modules/exclude b/modules/exclude index 8adae5400f..92f8d3c472 100644 --- a/modules/exclude +++ b/modules/exclude @@ -13,7 +13,7 @@ fnmatch fopen-gnu hash mbscasecmp -mbuiter +mbuiter [test "$GNULIB_MCEL_PREFER" != yes] nullptr regex stdbool -- 2.39.5