From: Brian Pane Date: Sun, 17 Mar 2002 17:35:39 +0000 (+0000) Subject: Performance fix for ap_ssi_get_tag_and_value: do a lightweight X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0a1c3b64b91c0bc7c83fee06250c59f94e711549;p=apache Performance fix for ap_ssi_get_tag_and_value: do a lightweight 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 --- diff --git a/modules/filters/mod_include.c b/modules/filters/mod_include.c index 8476b75b4e..0b9d1c92fa 100644 --- a/modules/filters/mod_include.c +++ b/modules/filters/mod_include.c @@ -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')); } }