aboutsummaryrefslogtreecommitdiffstats
path: root/lib/string.c
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2015-02-13 17:36:44 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-14 00:21:36 -0500
commit8da53d4595a53fb9a3380dd4d1c9bc24c7c9aab8 (patch)
tree82207634de679fd96287b82ecb9bb5da205a8c2a /lib/string.c
parentfcc139ae227b97bd81352e9102d8e79498d1e930 (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/string.c')
-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);
313 */ 313 */
314char *strrchr(const char *s, int c) 314char *strrchr(const char *s, int c)
315{ 315{
316 const char *p = s + strlen(s); 316 const char *last = NULL;
317 do { 317 do {
318 if (*p == (char)c) 318 if (*s == (char)c)
319 return (char *)p; 319 last = s;
320 } while (--p >= s); 320 } while (*s++);
321 return NULL; 321 return (char *)last;
322} 322}
323EXPORT_SYMBOL(strrchr); 323EXPORT_SYMBOL(strrchr);
324#endif 324#endif