summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2015-02-13 23:36:44 +0100
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-14 06:21:36 +0100
commit8da53d4595a53fb9a3380dd4d1c9bc24c7c9aab8 (patch)
tree82207634de679fd96287b82ecb9bb5da205a8c2a /lib
parentfs/namespace: convert devname allocation to kstrdup_const (diff)
downloadlinux-8da53d4595a53fb9a3380dd4d1c9bc24c7c9aab8.tar.xz
linux-8da53d4595a53fb9a3380dd4d1c9bc24c7c9aab8.zip
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/string.c b/lib/string.c
index 3206d0178296..cdd97f431ae2 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -313,12 +313,12 @@ EXPORT_SYMBOL(strchrnul);
*/
char *strrchr(const char *s, int c)
{
- const char *p = s + strlen(s);
- do {
- if (*p == (char)c)
- return (char *)p;
- } while (--p >= s);
- return NULL;
+ const char *last = NULL;
+ do {
+ if (*s == (char)c)
+ last = s;
+ } while (*s++);
+ return (char *)last;
}
EXPORT_SYMBOL(strrchr);
#endif