[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a903947619f94dfa88d3dd147b7a5e95@AcuMS.aculab.com>
Date: Sat, 28 Jan 2023 14:51:47 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Andy Shevchenko' <andriy.shevchenko@...ux.intel.com>,
Kees Cook <keescook@...omium.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
CC: Andy Shevchenko <andy@...nel.org>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: RE: [PATCH v1 1/1] lib/string: Use strchr() in strpbrk()
From: Andy Shevchenko
> Sent: 27 January 2023 15:52
>
> 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().
Except that you get a whole load of calls to strchr() for (typically)
very few characters.
So the cost of the calls dominates, anything that tries to speed up
strchr() for long strings will also slow things down.
Plausibly this version (untested) is faster!
char *strbprk(const char *str, const char *seps)
{
const char *found, *try;
do {
if (*!seps)
return NULL;
found = strchr(str, *seps++);
} while (!found);
while (*seps) {
try = memchr(str, *seps++, found - str);
if (try)
found = try;
}
return (char *)found;
}
Although I very much doubt strpbrk() is used anywhere where
performance matters.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists