From ca9fb36b7386638532269adf6d5e9b8121325f01 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 16 Jun 2015 07:43:08 -0700 Subject: [PATCH] Implement gpr_slice_buffer_move_into --- src/core/support/slice_buffer.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/core/support/slice_buffer.c b/src/core/support/slice_buffer.c index 91b5d8c98b2..f54aca8cfe0 100644 --- a/src/core/support/slice_buffer.c +++ b/src/core/support/slice_buffer.c @@ -190,3 +190,19 @@ void gpr_slice_buffer_swap(gpr_slice_buffer *a, gpr_slice_buffer *b) { GPR_SWAP(gpr_slice *, a->slices, b->slices); } } + +void gpr_slice_buffer_move_into(gpr_slice_buffer *src, gpr_slice_buffer *dst) { + /* anything to move? */ + if (src->count == 0) { + return; + } + /* anything in dst? */ + if (dst->count == 0) { + gpr_slice_buffer_swap(src, dst); + return; + } + /* both buffers have data - copy, and reset src */ + gpr_slice_buffer_addn(dst, src->slices, src->count); + src->count = 0; + src->length = 0; +}