From: Graham Leggett Date: Thu, 23 May 2013 14:17:56 +0000 (+0000) Subject: core: speed up (for common cases) and reduce memory usage of ap_escape_logitem X-Git-Tag: 2.4.5~245 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e794edc5db956540942746b7185d2a7d0da11829;p=apache 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 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 --- diff --git a/CHANGES b/CHANGES index a8774a9c46..6dbdee954c 100644 --- 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 ] diff --git a/STATUS b/STATUS index 99f4ba2bc9..5fe6642a43 100644 --- 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 ] diff --git a/server/util.c b/server/util.c index a643c863f3..c97c77857f 100644 --- a/server/util.c +++ b/server/util.c @@ -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) {