This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 3/*] Use strchrnul for strcspn (x, "c")
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Sun, 24 May 2015 17:40:17 +0200
- Subject: Re: [PATCH 3/*] Use strchrnul for strcspn (x, "c")
- Authentication-results: sourceware.org; auth=none
- References: <20150524150715 dot GA31589 at domone>
A loop there is clearly suboptimal. We improve performance by using
strchrnul equivalent.
OK to commit?
* string/bits/string2.h (__strcspn_c1): Optimize with __strchrnul.
diff --git a/string/bits/string2.h b/string/bits/string2.h
index a595c74..2fe67b3 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -277,10 +277,7 @@ __STRING_INLINE size_t __strcspn_c1 (const char *__s, int __reject);
__STRING_INLINE size_t
__strcspn_c1 (const char *__s, int __reject)
{
- size_t __result = 0;
- while (__s[__result] != '\0' && __s[__result] != __reject)
- ++__result;
- return __result;
+ return __strchrnul (__s, __reject) - __s;
}
__STRING_INLINE size_t __strcspn_c2 (const char *__s, int __reject1,