From 649deebf7f50d29ed3550ce9dcd241cbeacb7df6 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 24 Sep 2015 23:19:40 -0700 Subject: Recycle partially filled buffers on the next read --- src/core/support/slice_buffer.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/core/support') diff --git a/src/core/support/slice_buffer.c b/src/core/support/slice_buffer.c index 8873d459d5..a1aa56fd72 100644 --- a/src/core/support/slice_buffer.c +++ b/src/core/support/slice_buffer.c @@ -208,7 +208,7 @@ void gpr_slice_buffer_move_into(gpr_slice_buffer *src, gpr_slice_buffer *dst) { src->length = 0; } -void gpr_slice_buffer_trim_end(gpr_slice_buffer *sb, size_t n) { +void gpr_slice_buffer_trim_end(gpr_slice_buffer *sb, size_t n, gpr_slice_buffer *garbage) { GPR_ASSERT(n <= sb->length); sb->length -= n; for (;;) { @@ -216,14 +216,15 @@ void gpr_slice_buffer_trim_end(gpr_slice_buffer *sb, size_t n) { gpr_slice slice = sb->slices[idx]; size_t slice_len = GPR_SLICE_LENGTH(slice); if (slice_len > n) { - sb->slices[idx] = gpr_slice_sub_no_ref(slice, 0, slice_len - n); + sb->slices[idx] = gpr_slice_split_head(&slice, slice_len - n); + gpr_slice_buffer_add_indexed(garbage, slice); return; } else if (slice_len == n) { - gpr_slice_unref(slice); + gpr_slice_buffer_add_indexed(garbage, slice); sb->count = idx; return; } else { - gpr_slice_unref(slice); + gpr_slice_buffer_add_indexed(garbage, slice); n -= slice_len; sb->count = idx; } -- cgit v1.2.3