[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <BAY105-F323FF3DC8E6C544A2BBE98FFD50@phx.gbl>
Date: Wed, 22 Aug 2007 11:34:49 +0200
From: "lode leroy" <lode_leroy@...mail.com>
To: linux-kernel@...r.kernel.org
Subject: [PATCH] memchr (trivial) optimization
While profiling something completely unrelated, I noticed
that on the workloads I used memchr for, I saw a 30%-40% improvement
in performance, with the following trivial changes...
(basically, it saves 3 operations for each call)
$ diff -Nurp linux/lib/string.c{-old,}
--- linux/lib/string.c-old 2007-08-22 11:18:54.000000000 +0200
+++ linux/lib/string.c 2007-08-22 11:19:20.000000000 +0200
@@ -623,10 +623,12 @@ EXPORT_SYMBOL(strstr);
void *memchr(const void *s, int c, size_t n)
{
const unsigned char *p = s;
- while (n-- != 0) {
- if ((unsigned char)c == *p++) {
- return (void *)(p - 1);
+ while (n != 0) {
+ if ((unsigned char)c == *p) {
+ return (void *)p;
}
+ n--;
+ p++;
}
return NULL;
}
_________________________________________________________________
A lot of passions? Collect all your personal info on one central location ,
for free! http://get.live.com/live/features
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists