]> granicus.if.org Git - apache/commitdiff
Performance fix for ap_ssi_get_tag_and_value: do a lightweight
authorBrian Pane <brianp@apache.org>
Sun, 17 Mar 2002 17:35:39 +0000 (17:35 +0000)
committerBrian Pane <brianp@apache.org>
Sun, 17 Mar 2002 17:35:39 +0000 (17:35 +0000)
scan through the tag value until/unless we reach a backslash
that necessitates the more complicated scanner loop.  In cases
where there isn't a backslash in the tag value, this reduces
the overhead of the scan from 5 comparisons per character to 3.

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

modules/filters/mod_include.c

index 8476b75b4ecf9f73f119a745994572a9493b226d..0b9d1c92fabf0dde1ee517cb0138e6319659eb04 100644 (file)
@@ -908,28 +908,46 @@ static void ap_ssi_get_tag_and_value(include_ctx_t *ctx, char **tag,
     }
     
     *tag_val = c;
-    while ((*c != '\0') &&
-           (((term != '\0') && (*c != term)) ||
-            ((term == '\0') && (!apr_isspace(*c))))) {
-        /* Accept \" (or ' or `) as valid quotation of string. 
-         */
-        if (*c == '\\') {  
-            /* Overwrite the "\" during the embedded 
-             * escape sequence of '"'. "\'" or '`'. 
-             * Shift bytes from here to next delimiter.     
+    if (!term) {
+        while (!apr_isspace(*c) && (*c != '\0')) {
+            c++;
+        }
+    }
+    else {
+        while ((*c != term) && (*c != '\0') && (*c != '\\')) {
+            /* Quickly scan past the string until we reach
+             * either the end of the tag or a backslash.  If
+             * we find a backslash, we have to switch to the
+             * more complicated parser loop that follows.
              */
             c++;
-            if (*c == term) {
-                shift_val++;
-            }
-            if (shift_val > 0) {
-                *(c-shift_val) = *c;
-            }
         }
+        if (*c == '\\') {
+            do {
+                /* Accept \" (or ' or `) as valid quotation of string. 
+                 */
+                if (*c == '\\') {  
+                    /* Overwrite the "\" during the embedded 
+                     * escape sequence of '"'. "\'" or '`'. 
+                     * Shift bytes from here to next delimiter.     
+                     */
+                    c++;
+                    if (*c == term) {
+                        shift_val++;
+                    }
+                    if (shift_val > 0) {
+                        *(c-shift_val) = *c;
+                    }
+                    if (*c == '\0') {
+                        break;
+                    }
+                }
 
-        c++;
-        if (shift_val > 0) {
-            *(c-shift_val) = *c;
+                c++;
+                if (shift_val > 0) {
+                    *(c-shift_val) = *c;
+                }
+            } while ((*c != term) && (*c != '\0'));
         }
     }