summaryrefslogtreecommitdiff
path: root/buckets
diff options
context:
space:
mode:
authorbrianp <brianp@13f79535-47bb-0310-9956-ffa450edef68>2002-05-12 21:45:27 +0000
committerbrianp <brianp@13f79535-47bb-0310-9956-ffa450edef68>2002-05-12 21:45:27 +0000
commit2b98e42e3330a1599288351590427b2f000b9369 (patch)
tree8cb1d5bb5bd8409321d847814839ac6c4710e39a /buckets
parentb89b3a61e7d81beb2a0b0e79b62d11c81dc74678 (diff)
downloadlibapr-util-2b98e42e3330a1599288351590427b2f000b9369.tar.gz
Optimization for apr_brigade_puts(): skip the strlen computation
in cases where a heap bucket at the end of the brigade has enough space to hold the string git-svn-id: http://svn.apache.org/repos/asf/apr/apr-util/trunk@58628 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'buckets')
-rw-r--r--buckets/apr_brigade.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/buckets/apr_brigade.c b/buckets/apr_brigade.c
index e7300a4b..7e3f4284 100644
--- a/buckets/apr_brigade.c
+++ b/buckets/apr_brigade.c
@@ -452,6 +452,31 @@ APU_DECLARE(apr_status_t) apr_brigade_puts(apr_bucket_brigade *b,
apr_brigade_flush flush, void *ctx,
const char *str)
{
+ apr_bucket *e = APR_BRIGADE_LAST(b);
+ if (!APR_BRIGADE_EMPTY(b) && APR_BUCKET_IS_HEAP(e)) {
+ /* If there is some space available in a heap bucket
+ * at the end of the brigade, start copying the string
+ */
+ apr_bucket_heap *h = e->data;
+ char *buf = h->base + e->start + e->length;
+ apr_size_t bytes_avail = h->alloc_len - e->length;
+ const char *s = str;
+
+ while (bytes_avail && *s) {
+ *buf++ = *s++;
+ bytes_avail--;
+ }
+ e->length += (s - str);
+ if (!*s) {
+ return APR_SUCCESS;
+ }
+ str = s;
+ }
+
+ /* If the string has not been copied completely to the brigade,
+ * delegate the remaining work to apr_brigade_write(), which
+ * knows how to grow the brigade
+ */
return apr_brigade_write(b, flush, ctx, str, strlen(str));
}