aboutsummaryrefslogtreecommitdiff
path: root/benchtests/bench-strnlen.c
diff options
context:
space:
mode:
Diffstat (limited to 'benchtests/bench-strnlen.c')
-rw-r--r--benchtests/bench-strnlen.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c
index b9039d5f3f..e9e51b27fc 100644
--- a/benchtests/bench-strnlen.c
+++ b/benchtests/bench-strnlen.c
@@ -21,6 +21,8 @@
# define TEST_NAME "strnlen"
#else
# define TEST_NAME "wcsnlen"
+# define generic_strnlen generic_wcsnlen
+# define memchr_strnlen wcschr_wcsnlen
#endif /* WIDE */
#include "bench-string.h"
@@ -28,27 +30,24 @@
#ifndef WIDE
# define MIDDLE_CHAR 127
-# define SIMPLE_STRNLEN simple_strnlen
#else
# define MIDDLE_CHAR 1121
-# define SIMPLE_STRNLEN simple_wcsnlen
#endif /* WIDE */
typedef size_t (*proto_t) (const CHAR *, size_t);
-size_t SIMPLE_STRNLEN (const CHAR *, size_t);
-
-IMPL (SIMPLE_STRNLEN, 0)
-IMPL (STRNLEN, 1)
+size_t generic_strnlen (const CHAR *, size_t);
size_t
-SIMPLE_STRNLEN (const CHAR *s, size_t maxlen)
+memchr_strnlen (const CHAR *s, size_t maxlen)
{
- size_t i;
-
- for (i = 0; i < maxlen && s[i]; ++i);
- return i;
+ const CHAR *s1 = MEMCHR (s, 0, maxlen);
+ return (s1 == NULL) ? maxlen : s1 - s;
}
+IMPL (STRNLEN, 1)
+IMPL (memchr_strnlen, 0)
+IMPL (generic_strnlen, 0)
+
static void
do_one_test (impl_t *impl, const CHAR *s, size_t maxlen, size_t exp_len)
{
@@ -146,3 +145,13 @@ test_main (void)
}
#include <support/test-driver.c>
+
+#define libc_hidden_def(X)
+#ifndef WIDE
+# undef STRNLEN
+# define STRNLEN generic_strnlen
+# include <string/strnlen.c>
+#else
+# define WCSNLEN generic_strnlen
+# include <wcsmbs/wcsnlen.c>
+#endif