]> granicus.if.org Git - apache/commitdiff
Save a few cycles and simlify code.
authorChristophe Jaillet <jailletc36@apache.org>
Fri, 4 May 2018 19:51:12 +0000 (19:51 +0000)
committerChristophe Jaillet <jailletc36@apache.org>
Fri, 4 May 2018 19:51:12 +0000 (19:51 +0000)
Use apr_pstrmemdup instead of apr_pstrndup when possible.
Avoid scanning the first 2 bytes when looking for the | delimiter. it is known to be "${".
Avoid comma separated statements, it is not that usual.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1830943 13f79535-47bb-0310-9956-ffa450edef68

modules/filters/mod_proxy_html.c

index 6a1ac07b180c030718d597a7d858768569818fa7..8e6989e2a427e6ab2a0bf08013c84814a7db51d2 100644 (file)
@@ -687,7 +687,7 @@ static meta *metafix(request_rec *r, const char *buf, apr_size_t len)
         p = buf+offs+pmatch[1].rm_eo;
         while (!apr_isalpha(*++p));
         for (q = p; apr_isalnum(*q) || (*q == '-'); ++q);
-        header = apr_pstrndup(r->pool, p, q-p);
+        header = apr_pstrmemdup(r->pool, p, q-p);
         if (!ap_cstr_casecmpn(header, "Content-Type", 12)) {
             ret = apr_palloc(r->pool, sizeof(meta));
             ret->start = offs+pmatch[0].rm_so;
@@ -744,27 +744,26 @@ static const char *interpolate_vars(request_rec *r, const char *str)
     const char *replacement;
     const char *var;
     for (;;) {
-        start = str;
-        if (start = ap_strstr_c(start, "${"), start == NULL)
+        if ((start = ap_strstr_c(str, "${")) == NULL)
             break;
 
-        if (end = ap_strchr_c(start+2, '}'), end == NULL)
+        if ((end = ap_strchr_c(start+2, '}')) == NULL)
             break;
 
-        delim = ap_strchr_c(start, '|');
+        delim = ap_strchr_c(start+2, '|');
 
         /* Restrict delim to ${...} */
         if (delim && delim >= end) {
             delim = NULL;
         }
 
-        before = apr_pstrndup(r->pool, str, start-str);
+        before = apr_pstrmemdup(r->pool, str, start-str);
         after = end+1;
         if (delim) {
-            var = apr_pstrndup(r->pool, start+2, delim-start-2);
+            var = apr_pstrmemdup(r->pool, start+2, delim-start-2);
         }
         else {
-            var = apr_pstrndup(r->pool, start+2, end-start-2);
+            var = apr_pstrmemdup(r->pool, start+2, end-start-2);
         }
         replacement = apr_table_get(r->subprocess_env, var);
         if (!replacement) {