brianp 02/05/12 14:45:27
Modified: buckets apr_brigade.c
Log:
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
Revision Changes Path
1.39 +25 -0 apr-util/buckets/apr_brigade.c
Index: apr_brigade.c
===================================================================
RCS file: /home/cvs/apr-util/buckets/apr_brigade.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- apr_brigade.c 10 Apr 2002 16:44:10 -0000 1.38
+++ apr_brigade.c 12 May 2002 21:45:27 -0000 1.39
@@ -452,6 +452,31 @@
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));
}