You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2008/04/17 16:09:36 UTC

svn commit: r649118 - in /httpd/httpd/branches/2.2.x: CHANGES STATUS docs/manual/mod/mod_substitute.xml modules/filters/mod_substitute.c

Author: jim
Date: Thu Apr 17 07:09:29 2008
New Revision: 649118

URL: http://svn.apache.org/viewvc?rev=649118&view=rev
Log:
Merge r627764, r628864 from trunk:

Change default of mod_substitute to flattening...
Via current discussion on dev@httpd


In the case where we have only 1 pattern, then we
can safely be quick, no matter what.

Reviewed by: jim

Modified:
    httpd/httpd/branches/2.2.x/CHANGES
    httpd/httpd/branches/2.2.x/STATUS
    httpd/httpd/branches/2.2.x/docs/manual/mod/mod_substitute.xml
    httpd/httpd/branches/2.2.x/modules/filters/mod_substitute.c

Modified: httpd/httpd/branches/2.2.x/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/CHANGES?rev=649118&r1=649117&r2=649118&view=diff
==============================================================================
--- httpd/httpd/branches/2.2.x/CHANGES [utf-8] (original)
+++ httpd/httpd/branches/2.2.x/CHANGES [utf-8] Thu Apr 17 07:09:29 2008
@@ -1,6 +1,11 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.2.9
 
+  *) mod_substitute: The default is now flattening the buckets after
+     each substitution. The newly added 'q' flag allows for the
+     quicker, more efficient bucket-splitting if the user so
+     desires. [Jim Jagielski]
+
   *) http_filters: Don't spin if get an error when reading the
      next chunk. PR 44381 [Ruediger Pluem]
 

Modified: httpd/httpd/branches/2.2.x/STATUS
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/STATUS?rev=649118&r1=649117&r2=649118&view=diff
==============================================================================
--- httpd/httpd/branches/2.2.x/STATUS (original)
+++ httpd/httpd/branches/2.2.x/STATUS Thu Apr 17 07:09:29 2008
@@ -88,15 +88,6 @@
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
- * mod_substitute: Make default behavior flattening of buckets. Allow
-   for people to specifically set "quick" mode.
-      Trunk version of patch:
-         http://svn.apache.org/viewvc?view=rev&revision=627764
-         http://svn.apache.org/viewvc?view=rev&revision=628864
-      Backport version for 2.2.x of patch:
-         Trunk version works (minus CHANGES conflict)
-    +1: jim, covener, wrowe
-
   * mod_speling: remove regression from 1.3/2.0 behavior and
     drop dependency between mod_speling and AcceptPathInfo.
     PR: 43562

Modified: httpd/httpd/branches/2.2.x/docs/manual/mod/mod_substitute.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/docs/manual/mod/mod_substitute.xml?rev=649118&r1=649117&r2=649118&view=diff
==============================================================================
--- httpd/httpd/branches/2.2.x/docs/manual/mod/mod_substitute.xml (original)
+++ httpd/httpd/branches/2.2.x/docs/manual/mod/mod_substitute.xml Thu Apr 17 07:09:29 2008
@@ -37,7 +37,7 @@
 <directivesynopsis>
 <name>Substitute</name>
 <description>Pattern to filter the response content</description>
-<syntax>Substitute <var>s/pattern/substitution/[inf]</var></syntax>
+<syntax>Substitute <var>s/pattern/substitution/[infq]</var></syntax>
 <contextlist><context>directory</context>
 <context>.htaccess</context></contextlist>
 <override>FileInfo</override>
@@ -59,7 +59,14 @@
         <dt><code>f</code></dt>
         <dd>The <code>f</code> flag causes mod_substitute to flatten the
         result of a substitution allowing for later substitutions to
-        take place on the boundary of this one.</dd>
+        take place on the boundary of this one. This is the default.</dd>
+        <dt><code>q</code></dt>
+        <dd>The <code>q</code> flag causes mod_substitute to not
+        flatten the buckets after each substitution. This can
+        result in much faster response and a decrease in memory
+        utilization, but should only be used if there is no possibility
+        that the result of one substitution will ever match a pattern
+        or regex of a subsequent one.</dd>
     </dl>
     
     <example><title>Example</title>

Modified: httpd/httpd/branches/2.2.x/modules/filters/mod_substitute.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/modules/filters/mod_substitute.c?rev=649118&r1=649117&r2=649118&view=diff
==============================================================================
--- httpd/httpd/branches/2.2.x/modules/filters/mod_substitute.c (original)
+++ httpd/httpd/branches/2.2.x/modules/filters/mod_substitute.c Thu Apr 17 07:09:29 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);
@@ -488,7 +496,7 @@
     subst_pattern_t *nscript;
     int is_pattern = 0;
     int ignore_case = 0;
-    int flatten = 0;
+    int flatten = 1;
     ap_regex_t *r = NULL;
 
     if (apr_tolower(*line) != 's') {
@@ -525,8 +533,10 @@
             is_pattern = 1;
         else if (delim == 'f')
             flatten = 1;
+        else if (delim == 'q')
+            flatten = 0;
         else
-            return "Bad Substitute flag, only s///[inf] are supported";
+            return "Bad Substitute flag, only s///[infq] are supported";
         flags++;
     }