apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1460346 - in /apr/apr-util/branches/1.5.x: ./ buckets/apr_brigade.c test/testbuckets.c
Date Sun, 24 Mar 2013 13:08:02 GMT
Author: sf
Date: Sun Mar 24 13:08:02 2013
New Revision: 1460346

URL: http://svn.apache.org/r1460346
Log:
Merge r1402903:

    Make apr_brigade_(v)putstrs more efficient by using apr_brigade_writev
    instead of apr_brigade_write

Modified:
    apr/apr-util/branches/1.5.x/   (props changed)
    apr/apr-util/branches/1.5.x/buckets/apr_brigade.c
    apr/apr-util/branches/1.5.x/test/testbuckets.c

Propchange: apr/apr-util/branches/1.5.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r1402903

Modified: apr/apr-util/branches/1.5.x/buckets/apr_brigade.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.5.x/buckets/apr_brigade.c?rev=1460346&r1=1460345&r2=1460346&view=diff
==============================================================================
--- apr/apr-util/branches/1.5.x/buckets/apr_brigade.c (original)
+++ apr/apr-util/branches/1.5.x/buckets/apr_brigade.c Sun Mar 24 13:08:02 2013
@@ -391,17 +391,30 @@ APU_DECLARE(apr_status_t) apr_brigade_vp
                                                void *ctx,
                                                va_list va)
 {
+#define MAX_VECS    8
+    struct iovec vec[MAX_VECS];
+    apr_size_t i = 0;
+
     for (;;) {
-        const char *str = va_arg(va, const char *);
+        char *str = va_arg(va, char *);
         apr_status_t rv;
 
         if (str == NULL)
             break;
 
-        rv = apr_brigade_write(b, flush, ctx, str, strlen(str));
-        if (rv != APR_SUCCESS)
-            return rv;
+        vec[i].iov_base = str;
+        vec[i].iov_len = strlen(str);
+        i++;
+
+        if (i == MAX_VECS) {
+            rv = apr_brigade_writev(b, flush, ctx, vec, i);
+            if (rv != APR_SUCCESS)
+                return rv;
+            i = 0;
+        }
     }
+    if (i != 0)
+       return apr_brigade_writev(b, flush, ctx, vec, i);
 
     return APR_SUCCESS;
 }

Modified: apr/apr-util/branches/1.5.x/test/testbuckets.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.5.x/test/testbuckets.c?rev=1460346&r1=1460345&r2=1460346&view=diff
==============================================================================
--- apr/apr-util/branches/1.5.x/test/testbuckets.c (original)
+++ apr/apr-util/branches/1.5.x/test/testbuckets.c Sun Mar 24 13:08:02 2013
@@ -488,6 +488,29 @@ static void test_write_split(abts_case *
     apr_bucket_alloc_destroy(ba);
 }
 
+static void test_write_putstrs(abts_case *tc, void *data)
+{
+    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
+    apr_bucket_brigade *bb = apr_brigade_create(p, ba);
+    apr_bucket *e;
+    char buf[30];
+    apr_size_t len = sizeof(buf);
+    const char *expect = "123456789abcdefghij";
+
+    e = apr_bucket_heap_create("1", 1, NULL, ba);
+    APR_BRIGADE_INSERT_HEAD(bb, e);
+
+    apr_brigade_putstrs(bb, NULL, NULL, "2", "34", "567", "8", "9a", "bcd",
+                        "e", "f", "gh", "i", NULL);
+    apr_brigade_putstrs(bb, NULL, NULL, "j", NULL);
+    apr_assert_success(tc, "apr_brigade_flatten",
+                       apr_brigade_flatten(bb, buf, &len));
+    ABTS_STR_NEQUAL(tc, expect, buf, strlen(expect));
+
+    apr_brigade_destroy(bb);
+    apr_bucket_alloc_destroy(ba);
+}
+
 abts_suite *testbuckets(abts_suite *suite)
 {
     suite = ADD_SUITE(suite);
@@ -504,6 +527,7 @@ abts_suite *testbuckets(abts_suite *suit
     abts_run_test(suite, test_truncfile, NULL);
     abts_run_test(suite, test_partition, NULL);
     abts_run_test(suite, test_write_split, NULL);
+    abts_run_test(suite, test_write_putstrs, NULL);
 
     return suite;
 }



Mime
View raw message