diff options
author | 2015-06-16 07:43:08 -0700 | |
---|---|---|
committer | 2015-06-16 07:43:08 -0700 | |
commit | ca9fb36b7386638532269adf6d5e9b8121325f01 (patch) | |
tree | b850dac8ccabb09fe4c64168359ec872bb9f4696 /src/core/support | |
parent | cfb5db927cb36c5958392dda6009532db661dc0a (diff) |
Implement gpr_slice_buffer_move_into
Diffstat (limited to 'src/core/support')
-rw-r--r-- | src/core/support/slice_buffer.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/core/support/slice_buffer.c b/src/core/support/slice_buffer.c index 91b5d8c98b..f54aca8cfe 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; +} |