lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
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

Powered by Openwall GNU/*/Linux Powered by OpenVZ