From 32c7acd46401530fdbd4e98508c9baaa705f8b53 Mon Sep 17 00:00:00 2001 From: Wilco Dijkstra Date: Fri, 3 Feb 2023 12:01:33 +0000 Subject: Replace rawmemchr (s, '\0') with strchr Almost all uses of rawmemchr find the end of a string. Since most targets use a generic implementation, replacing it with strchr is better since that is optimized by compilers into strlen (s) + s. Also fix the generic rawmemchr implementation to use a cast to unsigned char in the if statement. Reviewed-by: Adhemerval Zanella --- benchtests/bench-rawmemchr.c | 2 +- benchtests/bench-strtok.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'benchtests') diff --git a/benchtests/bench-rawmemchr.c b/benchtests/bench-rawmemchr.c index f6398f86d9..088c516e59 100644 --- a/benchtests/bench-rawmemchr.c +++ b/benchtests/bench-rawmemchr.c @@ -30,7 +30,7 @@ typedef char *(*proto_t) (const char *, int); char * generic_rawmemchr (const char *s, int c) { - if (c != 0) + if ((unsigned char) c != 0) return memchr (s, c, PTRDIFF_MAX); return (char *)s + strlen (s); } diff --git a/benchtests/bench-strtok.c b/benchtests/bench-strtok.c index 10260e9b47..711bdaab58 100644 --- a/benchtests/bench-strtok.c +++ b/benchtests/bench-strtok.c @@ -42,7 +42,7 @@ oldstrtok (char *s, const char *delim) s = strpbrk (token, delim); if (s == NULL) /* This token finishes the string. */ - olds = rawmemchr (token, '\0'); + olds = strchr (token, '\0'); else { /* Terminate the token and make OLDS point past it. */ -- cgit 1.4.1