|
|
@ -314,7 +314,7 @@ grpc_slice grpc_slice_sub(grpc_slice source, size_t begin, size_t end) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice *source, size_t split, |
|
|
|
grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice *source, size_t split, |
|
|
|
int incref) { |
|
|
|
grpc_slice_ref_whom ref_whom) { |
|
|
|
grpc_slice tail; |
|
|
|
grpc_slice tail; |
|
|
|
|
|
|
|
|
|
|
|
if (source->refcount == NULL) { |
|
|
|
if (source->refcount == NULL) { |
|
|
@ -328,26 +328,36 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice *source, size_t split, |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
size_t tail_length = source->data.refcounted.length - split; |
|
|
|
size_t tail_length = source->data.refcounted.length - split; |
|
|
|
GPR_ASSERT(source->data.refcounted.length >= split); |
|
|
|
GPR_ASSERT(source->data.refcounted.length >= split); |
|
|
|
if (tail_length < sizeof(tail.data.inlined.bytes)) { |
|
|
|
if (tail_length < sizeof(tail.data.inlined.bytes) && |
|
|
|
|
|
|
|
ref_whom != GRPC_SLICE_REF_TAIL) { |
|
|
|
/* Copy out the bytes - it'll be cheaper than refcounting */ |
|
|
|
/* Copy out the bytes - it'll be cheaper than refcounting */ |
|
|
|
tail.refcount = NULL; |
|
|
|
tail.refcount = NULL; |
|
|
|
tail.data.inlined.length = (uint8_t)tail_length; |
|
|
|
tail.data.inlined.length = (uint8_t)tail_length; |
|
|
|
memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split, |
|
|
|
memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split, |
|
|
|
tail_length); |
|
|
|
tail_length); |
|
|
|
|
|
|
|
source->refcount = source->refcount->sub_refcount; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
/* Build the result */ |
|
|
|
/* Build the result */ |
|
|
|
if (incref) { |
|
|
|
switch (ref_whom) { |
|
|
|
|
|
|
|
case GRPC_SLICE_REF_TAIL: |
|
|
|
|
|
|
|
tail.refcount = source->refcount->sub_refcount; |
|
|
|
|
|
|
|
source->refcount = &noop_refcount; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case GRPC_SLICE_REF_HEAD: |
|
|
|
|
|
|
|
tail.refcount = &noop_refcount; |
|
|
|
|
|
|
|
source->refcount = source->refcount->sub_refcount; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case GRPC_SLICE_REF_BOTH: |
|
|
|
tail.refcount = source->refcount->sub_refcount; |
|
|
|
tail.refcount = source->refcount->sub_refcount; |
|
|
|
|
|
|
|
source->refcount = source->refcount->sub_refcount; |
|
|
|
/* Bump the refcount */ |
|
|
|
/* Bump the refcount */ |
|
|
|
tail.refcount->vtable->ref(tail.refcount); |
|
|
|
tail.refcount->vtable->ref(tail.refcount); |
|
|
|
} else { |
|
|
|
break; |
|
|
|
tail.refcount = &noop_refcount; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
/* Point into the source array */ |
|
|
|
/* Point into the source array */ |
|
|
|
tail.data.refcounted.bytes = source->data.refcounted.bytes + split; |
|
|
|
tail.data.refcounted.bytes = source->data.refcounted.bytes + split; |
|
|
|
tail.data.refcounted.length = tail_length; |
|
|
|
tail.data.refcounted.length = tail_length; |
|
|
|
} |
|
|
|
} |
|
|
|
source->refcount = source->refcount->sub_refcount; |
|
|
|
|
|
|
|
source->data.refcounted.length = split; |
|
|
|
source->data.refcounted.length = split; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -355,7 +365,7 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice *source, size_t split, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) { |
|
|
|
grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) { |
|
|
|
return grpc_slice_split_tail_maybe_ref(source, split, true); |
|
|
|
return grpc_slice_split_tail_maybe_ref(source, split, GRPC_SLICE_REF_BOTH); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { |
|
|
|
grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { |
|
|
|