httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r628864 - /httpd/httpd/trunk/modules/filters/mod_substitute.c
Date Mon, 18 Feb 2008 20:45:39 GMT
Author: jim
Date: Mon Feb 18 12:45:34 2008
New Revision: 628864

URL: http://svn.apache.org/viewvc?rev=628864&view=rev
Log:
In the case where we have only 1 pattern, then we
can safely be quick, no matter what.

Modified:
    httpd/httpd/trunk/modules/filters/mod_substitute.c

Modified: httpd/httpd/trunk/modules/filters/mod_substitute.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/filters/mod_substitute.c?rev=628864&r1=628863&r2=628864&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/filters/mod_substitute.c (original)
+++ httpd/httpd/trunk/modules/filters/mod_substitute.c Mon Feb 18 12:45:34 2008
@@ -103,6 +103,7 @@
                          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 @@
     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 @@
                     {
                         /* 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 @@
                         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 @@
                         /* 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 @@
                          */
                         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);



Mime
View raw message