You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rp...@apache.org on 2019/06/28 08:50:31 UTC

svn commit: r1862270 - in /httpd/httpd/trunk/modules/dav: fs/dbm.c fs/repos.c main/mod_dav.c main/props.c main/std_liveprop.c main/util.c

Author: rpluem
Date: Fri Jun 28 08:50:31 2019
New Revision: 1862270

URL: http://svn.apache.org/viewvc?rev=1862270&view=rev
Log:
* Replace apr_psprintf with apr_pstrcat where the format strings only
  contain %s to improve efficiency. Leave out error messages as they
  are not on a crtical code path and error message become less readable
  when taking out the format specifiers.

Modified:
    httpd/httpd/trunk/modules/dav/fs/dbm.c
    httpd/httpd/trunk/modules/dav/fs/repos.c
    httpd/httpd/trunk/modules/dav/main/mod_dav.c
    httpd/httpd/trunk/modules/dav/main/props.c
    httpd/httpd/trunk/modules/dav/main/std_liveprop.c
    httpd/httpd/trunk/modules/dav/main/util.c

Modified: httpd/httpd/trunk/modules/dav/fs/dbm.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/dav/fs/dbm.c?rev=1862270&r1=1862269&r2=1862270&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/dav/fs/dbm.c (original)
+++ httpd/httpd/trunk/modules/dav/fs/dbm.c Fri Jun 28 08:50:31 2019
@@ -355,29 +355,33 @@ static void dav_append_prop(apr_pool_t *
         /* the property is an empty value */
         if (*name == ':') {
             /* "no namespace" case */
-            s = apr_psprintf(pool, "<%s/>" DEBUG_CR, name+1);
+            s = apr_pstrcat(pool, "<", name+1, "/>" DEBUG_CR, NULL);
         }
         else {
-            s = apr_psprintf(pool, "<ns%s/>" DEBUG_CR, name);
+            s = apr_pstrcat(pool, "<ns", name, "/>" DEBUG_CR, NULL);
         }
     }
     else if (*lang != '\0') {
         if (*name == ':') {
             /* "no namespace" case */
-            s = apr_psprintf(pool, "<%s xml:lang=\"%s\">%s</%s>" DEBUG_CR,
-                             name+1, lang, value, name+1);
+            s = apr_pstrcat(pool, "<", name+1, " xml:lang=\"",
+                            lang, "\">", value, "</", name+1, ">" DEBUG_CR,
+                            NULL);
         }
         else {
-            s = apr_psprintf(pool, "<ns%s xml:lang=\"%s\">%s</ns%s>" DEBUG_CR,
-                             name, lang, value, name);
+            s = apr_pstrcat(pool, "<ns", name, " xml:lang=\"",
+                            lang, "\">", value, "</ns", name, ">" DEBUG_CR,
+                            NULL);
         }
     }
     else if (*name == ':') {
         /* "no namespace" case */
-        s = apr_psprintf(pool, "<%s>%s</%s>" DEBUG_CR, name+1, value, name+1);
+        s = apr_pstrcat(pool, "<", name+1, ">", value, "</", name+1, ">"
+                        DEBUG_CR, NULL);
     }
     else {
-        s = apr_psprintf(pool, "<ns%s>%s</ns%s>" DEBUG_CR, name, value, name);
+        s = apr_pstrcat(pool, "<ns", name, ">", value, "</ns", name, ">"
+                        DEBUG_CR, NULL);
     }
 
     apr_text_append(pool, phdr, s);

Modified: httpd/httpd/trunk/modules/dav/fs/repos.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/dav/fs/repos.c?rev=1862270&r1=1862269&r2=1862270&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/dav/fs/repos.c (original)
+++ httpd/httpd/trunk/modules/dav/fs/repos.c Fri Jun 28 08:50:31 2019
@@ -2002,10 +2002,12 @@ static dav_prop_insert dav_fs_insert_pro
     }
     else {
         /* assert: what == DAV_PROP_INSERT_SUPPORTED */
-        s = apr_psprintf(p,
-                         "<D:supported-live-property D:name=\"%s\" "
-                         "D:namespace=\"%s\"/>" DEBUG_CR,
-                         info->name, dav_fs_namespace_uris[info->ns]);
+        s = apr_pstrcat(p,
+                        "<D:supported-live-property D:name=\"",
+                        info->name,
+                        "\" D:namespace=\"",
+                        dav_fs_namespace_uris[info->ns],
+                        "\"/>" DEBUG_CR, NULL);
     }
     apr_text_append(p, phdr, s);
 

Modified: httpd/httpd/trunk/modules/dav/main/mod_dav.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/dav/main/mod_dav.c?rev=1862270&r1=1862269&r2=1862270&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/dav/main/mod_dav.c (original)
+++ httpd/httpd/trunk/modules/dav/main/mod_dav.c Fri Jun 28 08:50:31 2019
@@ -669,8 +669,8 @@ static int dav_created(request_rec *r, c
 
     /* Apache doesn't allow us to set a variable body for HTTP_CREATED, so
      * we must manufacture the entire response. */
-    body = apr_psprintf(r->pool, "%s %s has been created.",
-                        what, ap_escape_html(r->pool, locn));
+    body = apr_pstrcat(r->pool, what, " ", ap_escape_html(r->pool, locn),
+                       " has been created.", NULL);
     return dav_error_response(r, HTTP_CREATED, body);
 }
 
@@ -1355,10 +1355,10 @@ static dav_error *dav_gen_supported_meth
             if (elts[i].key == NULL)
                 continue;
 
-            s = apr_psprintf(r->pool,
-                             "<D:supported-method D:name=\"%s\"/>"
-                             DEBUG_CR,
-                             elts[i].key);
+            s = apr_pstrcat(r->pool,
+                            "<D:supported-method D:name=\"",
+                            elts[i].key,
+                            "\"/>" DEBUG_CR, NULL);
             apr_text_append(r->pool, body, s);
         }
     }
@@ -1384,10 +1384,9 @@ static dav_error *dav_gen_supported_meth
 
                 /* see if method is supported */
                 if (apr_table_get(methods, name) != NULL) {
-                    s = apr_psprintf(r->pool,
-                                     "<D:supported-method D:name=\"%s\"/>"
-                                     DEBUG_CR,
-                                     name);
+                    s = apr_pstrcat(r->pool,
+                                    "<D:supported-method D:name=\"",
+                                    name, "\"/>" DEBUG_CR, NULL);
                     apr_text_append(r->pool, body, s);
                 }
             }
@@ -1519,10 +1518,12 @@ static dav_error *dav_gen_supported_repo
                 for (rp = reports; rp->nmspace != NULL; ++rp) {
                     /* Note: we presume reports->namespace is
                      * properly XML/URL quoted */
-                    s = apr_psprintf(r->pool,
-                                     "<D:supported-report D:name=\"%s\" "
-                                     "D:namespace=\"%s\"/>" DEBUG_CR,
-                                     rp->name, rp->nmspace);
+                    s = apr_pstrcat(r->pool,
+                                    "<D:supported-report D:name=\"",
+                                    rp->name,
+                                    "\" D:namespace=\"",
+                                    rp->nmspace,
+                                    "\"/>" DEBUG_CR, NULL);
                     apr_text_append(r->pool, body, s);
                 }
             }
@@ -1560,12 +1561,13 @@ static dav_error *dav_gen_supported_repo
                                 /* Note: we presume reports->nmspace is
                                  * properly XML/URL quoted
                                  */
-                                s = apr_psprintf(r->pool,
-                                                 "<D:supported-report "
-                                                 "D:name=\"%s\" "
-                                                 "D:namespace=\"%s\"/>"
-                                                 DEBUG_CR,
-                                                 rp->name, rp->nmspace);
+                                s = apr_pstrcat(r->pool,
+                                                "<D:supported-report "
+                                                "D:name=\"",
+                                                rp->name,
+                                                "\" D:namespace=\"",
+                                                rp->nmspace,
+                                                "\"/>" DEBUG_CR, NULL);
                                 apr_text_append(r->pool, body, s);
                                 break;
                             }
@@ -2742,7 +2744,7 @@ static int dav_method_copymove(request_r
         const char *nscp_path = apr_table_get(r->headers_in, "New-uri");
 
         if (nscp_host != NULL && nscp_path != NULL)
-            dest = apr_psprintf(r->pool, "http://%s%s", nscp_host, nscp_path);
+            dest = apr_pstrcat(r->pool, "http://", nscp_host, nscp_path, NULL);
     }
     if (dest == NULL) {
         /* This supplies additional information for the default message. */

Modified: httpd/httpd/trunk/modules/dav/main/props.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/dav/main/props.c?rev=1862270&r1=1862269&r2=1862270&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/dav/main/props.c (original)
+++ httpd/httpd/trunk/modules/dav/main/props.c Fri Jun 28 08:50:31 2019
@@ -421,18 +421,18 @@ static dav_error * dav_insert_coreprop(d
             /* use D: prefix to refer to the DAV: namespace URI,
              * and let the namespace attribute default to "DAV:"
              */
-            s = apr_psprintf(propdb->p,
-                            "<D:supported-live-property D:name=\"%s\"/>" DEBUG_CR,
-                            name);
+            s = apr_pstrcat(propdb->p,
+                            "<D:supported-live-property D:name=\"",
+                            name, "\"/>" DEBUG_CR, NULL);
         }
         else if (what == DAV_PROP_INSERT_VALUE && *value != '\0') {
             /* use D: prefix to refer to the DAV: namespace URI */
-            s = apr_psprintf(propdb->p, "<D:%s>%s</D:%s>" DEBUG_CR,
-                            name, value, name);
+            s = apr_pstrcat(propdb->p, "<D:", name, ">", value, "</D:", name,
+                            ">" DEBUG_CR, NULL);
         }
         else {
             /* use D: prefix to refer to the DAV: namespace URI */
-            s = apr_psprintf(propdb->p, "<D:%s/>" DEBUG_CR, name);
+            s = apr_pstrcat(propdb->p, "<D:", name, "/>" DEBUG_CR, NULL);
         }
         apr_text_append(propdb->p, phdr, s);
 
@@ -473,11 +473,11 @@ static void dav_output_prop_name(apr_poo
     const char *s;
 
     if (*name->ns == '\0')
-        s = apr_psprintf(pool, "<%s/>" DEBUG_CR, name->name);
+        s = apr_pstrcat(pool, "<", name->name, "/>" DEBUG_CR, NULL);
     else {
         const char *prefix = dav_xmlns_add_uri(xi, name->ns);
 
-        s = apr_psprintf(pool, "<%s:%s/>" DEBUG_CR, prefix, name->name);
+        s = apr_pstrcat(pool, "<", prefix, ":", name->name, "/>" DEBUG_CR, NULL);
     }
 
     apr_text_append(pool, phdr, s);

Modified: httpd/httpd/trunk/modules/dav/main/std_liveprop.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/dav/main/std_liveprop.c?rev=1862270&r1=1862269&r2=1862270&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/dav/main/std_liveprop.c (original)
+++ httpd/httpd/trunk/modules/dav/main/std_liveprop.c Fri Jun 28 08:50:31 2019
@@ -154,10 +154,10 @@ static dav_prop_insert dav_core_insert_p
     /* assert: info != NULL && info->name != NULL */
 
     if (what == DAV_PROP_INSERT_SUPPORTED) {
-        s = apr_psprintf(p,
-                         "<D:supported-live-property D:name=\"%s\" "
-                         "D:namespace=\"%s\"/>" DEBUG_CR,
-                         info->name, dav_core_namespace_uris[info->ns]);
+        s = apr_pstrcat(p,
+                         "<D:supported-live-property D:name=\"", info->name,
+                         "\" D:namespace=\"", dav_core_namespace_uris[info->ns],
+                         "\"/>" DEBUG_CR, NULL);
     }
     else if (what == DAV_PROP_INSERT_VALUE && *value != '\0') {
         s = apr_psprintf(p, "<lp%ld:%s>%s</lp%ld:%s>" DEBUG_CR,

Modified: httpd/httpd/trunk/modules/dav/main/util.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/dav/main/util.c?rev=1862270&r1=1862269&r2=1862270&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/dav/main/util.c (original)
+++ httpd/httpd/trunk/modules/dav/main/util.c Fri Jun 28 08:50:31 2019
@@ -470,8 +470,8 @@ DAV_DECLARE(void) dav_xmlns_generate(dav
 
         apr_hash_this(hi, &prefix, NULL, &uri);
 
-        s = apr_psprintf(xi->pool, " xmlns:%s=\"%s\"",
-                         (const char *)prefix, (const char *)uri);
+        s = apr_pstrcat(xi->pool, " xmlns:", (const char *)prefix, "=\"",
+                        (const char *)uri, "\"", NULL);
         apr_text_append(xi->pool, phdr, s);
     }
 }



Re: svn commit: r1862270 - in /httpd/httpd/trunk/modules/dav: fs/dbm.c fs/repos.c main/mod_dav.c main/props.c main/std_liveprop.c main/util.c

Posted by Ruediger Pluem <rp...@apache.org>.

On 6/29/20 5:52 PM, Graham Leggett wrote:
> On 28 Jun 2019, at 10:50, rpluem@apache.org <ma...@apache.org> wrote:
> 
>> * Replace apr_psprintf with apr_pstrcat where the format strings only
>>  contain %s to improve efficiency. Leave out error messages as they
>>  are not on a crtical code path and error message become less readable
>>  when taking out the format specifiers.
> 
> I’ve proposed this for backport, as it blocks other dav changes. Would it be possible to take a look?

Voted.

Regards

Rüdiger


Re: svn commit: r1862270 - in /httpd/httpd/trunk/modules/dav: fs/dbm.c fs/repos.c main/mod_dav.c main/props.c main/std_liveprop.c main/util.c

Posted by Graham Leggett <mi...@sharp.fm>.
On 28 Jun 2019, at 10:50, rpluem@apache.org wrote:

> * Replace apr_psprintf with apr_pstrcat where the format strings only
>  contain %s to improve efficiency. Leave out error messages as they
>  are not on a crtical code path and error message become less readable
>  when taking out the format specifiers.

I’ve proposed this for backport, as it blocks other dav changes. Would it be possible to take a look?

Regards,
Graham
—