mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-27 17:11:46 +00:00
lib/string.c: improve strrchr()
Instead of potentially passing over the string twice in case c is not found, just keep track of the last occurrence. According to bloat-o-meter, this also cuts the generated code by a third (54 vs 36 bytes). Oh, and we get rid of those 7-space indented lines. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
fcc139ae22
commit
8da53d4595
1 changed files with 6 additions and 6 deletions
10
lib/string.c
10
lib/string.c
|
@ -313,12 +313,12 @@ EXPORT_SYMBOL(strchrnul);
|
||||||
*/
|
*/
|
||||||
char *strrchr(const char *s, int c)
|
char *strrchr(const char *s, int c)
|
||||||
{
|
{
|
||||||
const char *p = s + strlen(s);
|
const char *last = NULL;
|
||||||
do {
|
do {
|
||||||
if (*p == (char)c)
|
if (*s == (char)c)
|
||||||
return (char *)p;
|
last = s;
|
||||||
} while (--p >= s);
|
} while (*s++);
|
||||||
return NULL;
|
return (char *)last;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(strrchr);
|
EXPORT_SYMBOL(strrchr);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue