aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2015-02-13 14:36:44 -0800
committerMister Oyster <oysterized@gmail.com>2017-04-11 10:57:09 +0200
commit9c55720b28bc8dfb3e5352e22a6487407891f782 (patch)
tree96b9766f06d24d58976c5656fb3f3e804fde5353 /lib
parenta3a2e604aea10bd20979fbac6415c3a8577d672a (diff)
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 517f9f36f..af0295f79 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -310,12 +310,12 @@ EXPORT_SYMBOL(strchr);
*/
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