diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-09-24 23:19:40 -0700 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-09-24 23:19:40 -0700 |
commit | 649deebf7f50d29ed3550ce9dcd241cbeacb7df6 (patch) | |
tree | 45225f74a8032867cc34f8f15823925ea97d699e /src/core/support | |
parent | fc193e1ff40d1ae557caf84d644a1b3a9bfe95b3 (diff) |
Recycle partially filled buffers on the next read
Diffstat (limited to 'src/core/support')
-rw-r--r-- | src/core/support/slice_buffer.c | 9 |
1 files changed, 5 insertions, 4 deletions
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; } |