httpd-bugs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 50920] New: using word wise comparison to improve string comparison
Date Sat, 12 Mar 2011 22:54:54 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=50920

           Summary: using word wise comparison to improve string
                    comparison
           Product: Apache httpd-2
           Version: 2.2.17
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: All
        AssignedTo: bugs@httpd.apache.org
        ReportedBy: songlinhai0543@gmail.com


There are many code fragments which compare two strings or one string with a
constant characters in httpd. These comparisons continue when two characters
are equal to each other, and stop when two characters are not equal. The whole
comparison process can be optimized by word-wise comparison. 

For example:

/httpd-2.2.17/modules/http/http_filters.c:592
        while (*b == '0') {

    /* Skip leading zeros */
    while (*b == '0') {
        ++b;
    }


can be optimized as:

while( *(unsigned int *)b == 0x30303030 ) {
   b += 4;
}

while( *b == '0')
{
   b ++;
}

in my unit test, if b has more than 4 '0' from the beginning, the patch will be
faster. And the optimization result will be more and more clear, when string b
has more '0' from the beginning. 

There are also other places which can be optimized in a similar way, and I list
them as follows:


/httpd-2.2.17/modules/generators/mod_autoindex.c:2169
   while (title_endp > title_name && *title_endp == '/') {
        *title_endp-- = '\0';
    }
==============================================================================
/httpd-2.2.17/modules/http/http_filters.c:592

/* Skip leading zeros */
    while (*b == '0') {
        ++b;
    }

===============================================================================
/httpd-2.2.17/modules/mappers/mod_alias.c:309
do {
                ++aliasp;
            } while (*aliasp == '/');

===============================================================================
/httpd-2.2.17/modules/mappers/mod_alias.c:312
  do {
                ++urip;
            } while (*urip == '/');
===============================================================================
/httpd-2.2.17/server/config.c:367

/* MIME type arguments */
            while (p2 > handler && p2[-1] == ' ')
                --p2; /* strip trailing spaces */

==============================================================================
/httpd-2.2.17/server/util_script.c:294
                while (lu && uri[lu-1] == '/') lu--;
==============================================================================
/httpd-2.2.17/server/protocol.c:507
 while ((uri[0] == '/') && (uri[1] == '/')) {
        ++uri ;
    }

==============================================================================
/httpd-2.2.17/server/core.c:3519

 while (*path == '/') {
            ++path;
        }

==============================================================================
/httpd-2.2.17/server/core.c:3542

while (*path == '/') {
            ++path;
        }

==============================================================================
/httpd-2.2.17/server/util.c:516

 do {
                ++s;
            } while (*s == '/');

=============================================================================
/httpd-2.2.17/srclib/apr/file_io/unix/filepath.c:73
do {
            ++(*inpath);
        } while (**inpath == '/');

=============================================================================
/httpd-2.2.17/srclib/apr/file_io/unix/filepath.c:164

 while (addpath[0] == '/')
            ++addpath;

=============================================================================
/httpd-2.2.17/srclib/apr/strings/apr_fnmatch.c:88

/* Collapse multiple stars. */
        while (c == '*') {
        c = *++pattern;
        }

==============================================================================
/httpd-2.2.17/srclib/apr/strings/apr_snprintf.c:187
   for (i = ndigit - 1; i > 0 && p1[i] == '0'; i--)
        ndigit--;

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


Mime
View raw message