Skip to content

Commit a8c5540

Browse files
andy-shevkees
authored andcommitted
lib/string: Use strchr() in strpbrk()
Use strchr() instead of open coding it as it's done elsewhere in the same file. Either we will have similar to what it was or possibly better performance in case architecture implements its own strchr(). Memory wise on x86_64 bloat-o-meter shows the following Function old new delta strsep 111 102 -9 Total: Before=2763, After=2754, chg -0.33% Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent aa85923 commit a8c5540

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lib/string.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,11 @@ EXPORT_SYMBOL(strcspn);
480480
*/
481481
char *strpbrk(const char *cs, const char *ct)
482482
{
483-
const char *sc1, *sc2;
483+
const char *sc;
484484

485-
for (sc1 = cs; *sc1 != '\0'; ++sc1) {
486-
for (sc2 = ct; *sc2 != '\0'; ++sc2) {
487-
if (*sc1 == *sc2)
488-
return (char *)sc1;
489-
}
485+
for (sc = cs; *sc != '\0'; ++sc) {
486+
if (strchr(ct, *sc))
487+
return (char *)sc;
490488
}
491489
return NULL;
492490
}

0 commit comments

Comments
 (0)