From ef634463b527880f074dd9d5a5733e24cc22d389 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 3 Jan 2010 00:22:25 +0100 Subject: [PATCH] [btr]: Add btr_merge_to(). --- buffer_tree.c | 14 +++++++++++++- buffer_tree.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/buffer_tree.c b/buffer_tree.c index 1cb295b4..2c02c694 100644 --- a/buffer_tree.c +++ b/buffer_tree.c @@ -309,7 +309,7 @@ void *btr_context(struct btr_node *btrn) * * This is a quite expensive operation. * - * \return The number of buffers that have been merged (zero, one or two). + * \return The number of buffers that have been available (zero, one or two). */ int btr_merge(struct btr_node *btrn) { @@ -351,3 +351,15 @@ int btr_merge(struct btr_node *btrn) para_list_add(&br->node, &btrn->input_queue); return 2; } + +void btr_merge_to(struct btr_node *btrn, size_t dest_size) +{ + for (;;) { + char *buf; + size_t len = btr_next_buffer(btrn, &buf); + if (len >= dest_size) + return; + if (btr_merge(btrn) < 2) + return; + } +} diff --git a/buffer_tree.h b/buffer_tree.h index 468b10d1..4d3502d5 100644 --- a/buffer_tree.h +++ b/buffer_tree.h @@ -20,3 +20,4 @@ void btr_splice_out_node(struct btr_node *btrn); void btr_pushdown(struct btr_node *btrn); void *btr_context(struct btr_node *btrn); int btr_merge(struct btr_node *btrn); +void btr_merge_to(struct btr_node *btrn, size_t dest_size); -- 2.39.5