Skip to content
Snippets Groups Projects
Commit 0a1c3b64 authored by Brian Pane's avatar Brian Pane
Browse files

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
parent 30541575
No related merge requests found
......@@ -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'));
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment