lkml.org 
[lkml]   [2007]   [Aug]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH] memchr (trivial) optimization
    Date
    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@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/
    \
     
     \ /
      Last update: 2007-08-22 11:37    [W:0.044 / U:31.480 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site