]> granicus.if.org Git - apache/commitdiff
Rearranged the code in mod_include's BNDM string-search function
authorBrian Pane <brianp@apache.org>
Wed, 26 Dec 2001 12:07:55 +0000 (12:07 +0000)
committerBrian Pane <brianp@apache.org>
Wed, 26 Dec 2001 12:07:55 +0000 (12:07 +0000)
for faster execution.

This new code short-circuits out of the inner scanning loop
after a single comparison when it hits a character not in the
"<!--#" pattern.  Compared to the previous code, this version
does more work for characters in the pattern and less work for
characters not in the pattern.  In practice, the net result
seems to be a speedup for typical shtml files, where characters
in the pattern are less common than characters not in the pattern.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92604 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/filters/mod_include.c

diff --git a/CHANGES b/CHANGES
index 23c88a87d21a95860cb52552329bdd7ba43a4e27..5c4bd81c6fb6ac895cb3641ad49e279d0f9ff875 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,7 @@
 Changes with Apache 2.0.30-dev
+  *) More performance tweaks to the BNDM string-search algorithm
+     used to find "<!--#" tokens in mod_include [Brian Pane]
+
   *) Miscellaneous small performance fixes: optimized away various
      string copy operations and removed large temp buffers from
      the stack [Brian Pane]
index cb6f51b051fdcb6111d5548c962e6c97e5d333aa..e2e27b5dff230e75c7014e96e7c794476d7ff158 100644 (file)
@@ -261,7 +261,7 @@ static apr_size_t bndm(const char *n, apr_size_t nl, const char *h,
     he = h + hl;
 
     T = t->T;
-    x = t->x << 1;
+    x = t->x;
 
     pi = h - 1; /* pi: p initial */
     p = pi + nl; /* compare window right to left. point to the first char */
@@ -270,14 +270,19 @@ static apr_size_t bndm(const char *n, apr_size_t nl, const char *h,
         skip = p;
         d = x;
         do {
-            d = (d >> 1) & T[(unsigned char) *p--];
+            d &= T[(unsigned char) *p--];
+            if (!d) {
+                break;
+            }
             if ((d & 1)) {
                 if (p != pi)
                     skip = p;
                 else
                     return p - h + 1;
             }
-        } while (d > 1);
+            d >>= 1;
+        } while (d);
+
         pi = skip;
         p = pi + nl;
     }