|
|
|
@ -51,19 +51,23 @@ static void maybe_embiggen(grpc_slice_buffer *sb) { |
|
|
|
|
size_t slice_count = sb->count + slice_offset; |
|
|
|
|
|
|
|
|
|
if (slice_count == sb->capacity) { |
|
|
|
|
sb->capacity = GROW(sb->capacity); |
|
|
|
|
GPR_ASSERT(sb->capacity > slice_count); |
|
|
|
|
if (sb->base_slices == sb->inlined) { |
|
|
|
|
sb->base_slices = gpr_malloc(sb->capacity * sizeof(grpc_slice)); |
|
|
|
|
memcpy(sb->base_slices, sb->inlined, slice_count * sizeof(grpc_slice)); |
|
|
|
|
sb->slices = sb->base_slices + slice_offset; |
|
|
|
|
if (sb->base_slices != sb->slices) { |
|
|
|
|
/* Make room by moving elements if there's still space unused */ |
|
|
|
|
memmove(sb->base_slices, sb->slices, sb->count * sizeof(grpc_slice)); |
|
|
|
|
sb->slices = sb->base_slices; |
|
|
|
|
} else { |
|
|
|
|
if (sb->base_slices != sb->slices) { |
|
|
|
|
memmove(sb->base_slices, sb->slices, sb->count * sizeof(grpc_slice)); |
|
|
|
|
/* Allocate more memory if no more space is available */ |
|
|
|
|
sb->capacity = GROW(sb->capacity); |
|
|
|
|
GPR_ASSERT(sb->capacity > slice_count); |
|
|
|
|
if (sb->base_slices == sb->inlined) { |
|
|
|
|
sb->base_slices = gpr_malloc(sb->capacity * sizeof(grpc_slice)); |
|
|
|
|
memcpy(sb->base_slices, sb->inlined, slice_count * sizeof(grpc_slice)); |
|
|
|
|
} else { |
|
|
|
|
sb->base_slices = |
|
|
|
|
gpr_realloc(sb->base_slices, sb->capacity * sizeof(grpc_slice)); |
|
|
|
|
} |
|
|
|
|
sb->base_slices = |
|
|
|
|
gpr_realloc(sb->base_slices, sb->capacity * sizeof(grpc_slice)); |
|
|
|
|
sb->slices = sb->base_slices; |
|
|
|
|
|
|
|
|
|
sb->slices = sb->base_slices + slice_offset; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|