Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8da53d45 authored by Rasmus Villemoes's avatar Rasmus Villemoes Committed by Linus Torvalds
Browse files

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: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent fcc139ae
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -313,12 +313,12 @@ EXPORT_SYMBOL(strchrnul);
 */
char *strrchr(const char *s, int c)
{
       const char *p = s + strlen(s);
	const char *last = NULL;
	do {
           if (*p == (char)c)
               return (char *)p;
       } while (--p >= s);
       return NULL;
		if (*s == (char)c)
			last = s;
	} while (*s++);
	return (char *)last;
}
EXPORT_SYMBOL(strrchr);
#endif