From 2e4062cd4660a080fc5182c4da313db0be7ac2b5 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Mon, 18 Feb 2008 20:45:34 +0000 Subject: [PATCH] In the case where we have only 1 pattern, then we can safely be quick, no matter what. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@628864 13f79535-47bb-0310-9956-ffa450edef68 --- modules/filters/mod_substitute.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/filters/mod_substitute.c b/modules/filters/mod_substitute.c index 9774369926..ebe860d66b 100644 --- a/modules/filters/mod_substitute.c +++ b/modules/filters/mod_substitute.c @@ -103,6 +103,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, apr_pool_t *tmp_pool) { int i; + int force_quick = 0; ap_regmatch_t regm[AP_MAX_REG_MATCH]; apr_size_t bytes; apr_size_t len; @@ -128,6 +129,13 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, apr_pool_create(&tpool, tmp_pool); scratch = NULL; fbytes = 0; + /* + * Simple optimization. If we only have one pattern, then + * we can safely avoid the overhead of flattening + */ + if (cfg->patterns->nelts == 1) { + force_quick = 1; + } for (i = 0; i < cfg->patterns->nelts; i++) { for (b = APR_BRIGADE_FIRST(mybb); b != APR_BRIGADE_SENTINEL(mybb); @@ -147,7 +155,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, { /* get offset into buff for pattern */ len = (apr_size_t) (repl - buff); - if (script->flatten) { + if (script->flatten && !force_quick) { /* * We are flattening the buckets here, meaning * that we don't do the fast bucket splits. @@ -181,7 +189,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, bytes -= len; buff += len; } - if (script->flatten && s1) { + if (script->flatten && s1 && !force_quick) { /* * we've finished looking at the bucket, so remove the * old one and add in our new one @@ -219,7 +227,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, /* first, grab the replacement string */ repl = ap_pregsub(tmp_pool, script->replacement, p, AP_MAX_REG_MATCH, regm); - if (script->flatten) { + if (script->flatten && !force_quick) { SEDSCAT(s1, s2, tmp_pool, p, regm[0].rm_so, repl); } else { @@ -236,7 +244,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, */ p += regm[0].rm_eo; } - if (script->flatten && s1) { + if (script->flatten && s1 && !force_quick) { s1 = apr_pstrcat(tmp_pool, s1, p, NULL); tmp_b = apr_bucket_transient_create(s1, strlen(s1), f->r->connection->bucket_alloc); -- 2.50.1