]> granicus.if.org Git - apache/commitdiff
core: speed up (for common cases) and reduce memory usage of ap_escape_logitem
authorGraham Leggett <minfrin@apache.org>
Thu, 23 May 2013 14:17:56 +0000 (14:17 +0000)
committerGraham Leggett <minfrin@apache.org>
Thu, 23 May 2013 14:17:56 +0000 (14:17 +0000)
This should save 70-100 bytes in the request pool for a default config.

trunk patch: http://svn.apache.org/r1485409
Submitted by: jailletc36
Reviewed by: jim, covener

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1485723 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
server/util.c

diff --git a/CHANGES b/CHANGES
index a8774a9c465f6f0a1a352de8a68ad38145fba90f..6dbdee954c17c56bd741517397a783f0aade4c56 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,10 @@
 
 Changes with Apache 2.4.5
 
+  *) core: speed up (for common cases) and reduce memory usage of
+     ap_escape_logitem(). This should save 70-100 bytes in the request
+     pool for a default config. [Christophe Jaillet]
+
   *) mod_dav: Ensure URI is correctly uriencoded on return. PR 54611
      [Timothy Wood <tjw omnigroup.com>]
 
diff --git a/STATUS b/STATUS
index 99f4ba2bc979d79753df353073b0ebcf292383cc..5fe6642a43db137dbb3229c02725880fc48f9540 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -90,11 +90,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-    * core: speed up (for common cases) and reduce memory usage of ap_escape_logitem
-      This should save 70-100 bytes in the request pool for a default config.
-      trunk patch: http://svn.apache.org/r1485409
-      2.4.x patch: trunk works
-      +1: jailletc36, jim, covener
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
   [ New proposals should be added at the end of the list ]
index a643c863f30fef9d707900c5d48dabdc38af9ad3..c97c77857f559db23d0b8457104cbd17964c1ba8 100644 (file)
@@ -1849,16 +1849,33 @@ AP_DECLARE(char *) ap_escape_logitem(apr_pool_t *p, const char *str)
     char *ret;
     unsigned char *d;
     const unsigned char *s;
+    apr_size_t length, escapes = 0;
 
     if (!str) {
         return NULL;
     }
 
-    ret = apr_palloc(p, 4 * strlen(str) + 1); /* Be safe */
+    /* Compute how many characters need to be escaped */
+    s = (const unsigned char *)str;
+    for (; *s; ++s) {
+        if (TEST_CHAR(*s, T_ESCAPE_LOGITEM)) {
+            escapes++;
+        }
+    }
+    
+    /* Compute the length of the input string, including NULL */
+    length = s - (const unsigned char *)str + 1;
+    
+    /* Fast path: nothing to escape */
+    if (escapes == 0) {
+        return apr_pmemdup(p, str, length);
+    }
+    
+    /* Each escaped character needs up to 3 extra bytes (0 --> \x00) */
+    ret = apr_palloc(p, length + 3 * escapes);
     d = (unsigned char *)ret;
     s = (const unsigned char *)str;
     for (; *s; ++s) {
-
         if (TEST_CHAR(*s, T_ESCAPE_LOGITEM)) {
             *d++ = '\\';
             switch(*s) {