Use peek_first instead of mutable_first.

Use DEBUG_ASSERT instead of ASSERT.
pull/18926/head
Soheil Hassas Yeganeh 6 years ago
parent fd5f787080
commit 4c0c2965fe
  1. 2
      src/core/ext/transport/chttp2/transport/frame_data.cc
  2. 2
      src/core/lib/compression/stream_compression_gzip.cc
  3. 3
      src/core/lib/security/transport/security_handshaker.cc
  4. 2
      src/core/lib/slice/slice_buffer.cc
  5. 2
      src/core/lib/slice/slice_internal.h
  6. 8
      test/core/slice/slice_buffer_test.cc

@ -104,7 +104,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
uint8_t* end = nullptr;
uint8_t* cur = nullptr;
grpc_slice* slice = grpc_slice_buffer_mutable_first(slices);
grpc_slice* slice = grpc_slice_buffer_peek_first(slices);
beg = GRPC_SLICE_START_PTR(*slice);
end = GRPC_SLICE_END_PTR(*slice);
cur = beg;

@ -53,7 +53,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx,
ctx->zs.avail_out = static_cast<uInt>(slice_size);
ctx->zs.next_out = GRPC_SLICE_START_PTR(slice_out);
while (ctx->zs.avail_out > 0 && in->length > 0 && !eoc) {
grpc_slice* slice = grpc_slice_buffer_mutable_first(in);
grpc_slice* slice = grpc_slice_buffer_peek_first(in);
ctx->zs.avail_in = static_cast<uInt> GRPC_SLICE_LENGTH(*slice);
ctx->zs.next_in = GRPC_SLICE_START_PTR(*slice);
r = ctx->flate(&ctx->zs, Z_NO_FLUSH);

@ -144,8 +144,7 @@ size_t SecurityHandshaker::MoveReadBufferIntoHandshakeBuffer() {
}
size_t offset = 0;
while (args_->read_buffer->count > 0) {
grpc_slice* next_slice =
grpc_slice_buffer_mutable_first(args_->read_buffer);
grpc_slice* next_slice = grpc_slice_buffer_peek_first(args_->read_buffer);
memcpy(handshake_buffer_ + offset, GRPC_SLICE_START_PTR(*next_slice),
GRPC_SLICE_LENGTH(*next_slice));
offset += GRPC_SLICE_LENGTH(*next_slice);

@ -371,7 +371,7 @@ grpc_slice grpc_slice_buffer_take_first(grpc_slice_buffer* sb) {
}
void grpc_slice_buffer_consume_first(grpc_slice_buffer* sb) {
GPR_ASSERT(sb->count > 0);
GPR_DEBUG_ASSERT(sb->count > 0);
sb->length -= GRPC_SLICE_LENGTH(sb->slices[0]);
grpc_slice_unref_internal(sb->slices[0]);
sb->slices++;

@ -243,7 +243,7 @@ void grpc_slice_buffer_partial_unref_internal(grpc_slice_buffer* sb,
void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb);
// Returns the first slice in the slice buffer.
inline grpc_slice* grpc_slice_buffer_mutable_first(grpc_slice_buffer* sb) {
inline grpc_slice* grpc_slice_buffer_peek_first(grpc_slice_buffer* sb) {
GPR_DEBUG_ASSERT(sb->count > 0);
return &sb->slices[0];
}

@ -119,25 +119,25 @@ void test_slice_buffer_first() {
grpc_slice_buffer_add_indexed(&buf, slices[idx]);
}
grpc_slice* first = grpc_slice_buffer_mutable_first(&buf);
grpc_slice* first = grpc_slice_buffer_peek_first(&buf);
GPR_ASSERT(GPR_SLICE_LENGTH(*first) == GPR_SLICE_LENGTH(slices[0]));
GPR_ASSERT(buf.count == 3);
GPR_ASSERT(buf.length == 12);
grpc_slice_buffer_sub_first(&buf, 1, 2);
first = grpc_slice_buffer_mutable_first(&buf);
first = grpc_slice_buffer_peek_first(&buf);
GPR_ASSERT(GPR_SLICE_LENGTH(*first) == 1);
GPR_ASSERT(buf.count == 3);
GPR_ASSERT(buf.length == 10);
grpc_slice_buffer_consume_first(&buf);
first = grpc_slice_buffer_mutable_first(&buf);
first = grpc_slice_buffer_peek_first(&buf);
GPR_ASSERT(GPR_SLICE_LENGTH(*first) == GPR_SLICE_LENGTH(slices[1]));
GPR_ASSERT(buf.count == 2);
GPR_ASSERT(buf.length == 9);
grpc_slice_buffer_consume_first(&buf);
first = grpc_slice_buffer_mutable_first(&buf);
first = grpc_slice_buffer_peek_first(&buf);
GPR_ASSERT(GPR_SLICE_LENGTH(*first) == GPR_SLICE_LENGTH(slices[2]));
GPR_ASSERT(buf.count == 1);
GPR_ASSERT(buf.length == 5);

Loading…
Cancel
Save