diff options
author | Nicolas Noble <nicolasnoble@users.noreply.github.com> | 2015-09-02 16:40:14 -0700 |
---|---|---|
committer | Nicolas Noble <nicolasnoble@users.noreply.github.com> | 2015-09-02 16:40:14 -0700 |
commit | aca3211b0f41aa862a424327de6d3a36e455a3c4 (patch) | |
tree | 2efde70412cb2d79c859a6b776ad18ca5d5c2f8f /src/core/support/slice_buffer.c | |
parent | bfe8719e78be1e51a98bbf6a555f40adcae3ea22 (diff) | |
parent | b059ae54c362833b287d4342cb96aae69792279f (diff) |
Merge pull request #3183 from ctiller/second-coming
Refactor Endpoint API
Diffstat (limited to 'src/core/support/slice_buffer.c')
-rw-r--r-- | src/core/support/slice_buffer.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/core/support/slice_buffer.c b/src/core/support/slice_buffer.c index 987d5cb9b5..6482ef9c9f 100644 --- a/src/core/support/slice_buffer.c +++ b/src/core/support/slice_buffer.c @@ -207,3 +207,25 @@ void gpr_slice_buffer_move_into(gpr_slice_buffer *src, gpr_slice_buffer *dst) { src->count = 0; src->length = 0; } + +void gpr_slice_buffer_trim_end(gpr_slice_buffer *sb, size_t n) { + GPR_ASSERT(n <= sb->length); + sb->length -= n; + for (;;) { + size_t idx = sb->count - 1; + 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); + return; + } else if (slice_len == n) { + gpr_slice_unref(slice); + sb->count = idx; + return; + } else { + gpr_slice_unref(slice); + n -= slice_len; + sb->count = idx; + } + } +} |