From: Alexey Dobriyan <adobriyan@gmail.com>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux@rasmusvillemoes.dk
Subject: [PATCH] un-improve strrchr()
Date: Sun, 28 Jun 2015 19:44:03 +0300 [thread overview]
Message-ID: <20150628164403.GA7169@p183.telecom.by> (raw)
In-Reply-To: <20150628163252.GA1991@p183.telecom.by>
Commit 8da53d4595a53fb9a3380dd4d1c9bc24c7c9aab8
("lib/string.c: improve strrchr()") changed strrchr() implementation
from "rewind to the end and search backwards" to "search forward"
optimizing for characher not found case. However, common case is exactly
the opposite: string is absolute pathname, c is '/' always to be found.
Previous code did 1 branch per character + 1 branch for every character
in the last path component. Current code does 2 branches per characher
regardless.
Patch reverts to previous implementation (sans fixed coding style).
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
Cc linux-kernel
lib/string.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
--- a/lib/string.c
+++ b/lib/string.c
@@ -313,12 +313,13 @@ EXPORT_SYMBOL(strchrnul);
*/
char *strrchr(const char *s, int c)
{
- const char *last = NULL;
+ const char *p = s + strlen(s);
+
do {
- if (*s == (char)c)
- last = s;
- } while (*s++);
- return (char *)last;
+ if (*p == (char)c)
+ return (char *)p;
+ } while (--p >= s);
+ return NULL;
}
EXPORT_SYMBOL(strrchr);
#endif
next parent reply other threads:[~2015-06-28 16:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20150628163252.GA1991@p183.telecom.by>
2015-06-28 16:44 ` Alexey Dobriyan [this message]
2015-06-28 18:01 ` [PATCH] un-improve strrchr() Joe Perches
2015-06-28 19:43 ` Alexey Dobriyan
2015-06-30 23:52 ` Chris Rorvick
2015-07-01 14:07 ` Alexey Dobriyan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150628164403.GA7169@p183.telecom.by \
--to=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).