diff options
author | 2017-04-12 13:15:45 -0700 | |
---|---|---|
committer | 2017-04-12 13:15:45 -0700 | |
commit | 423d6fd7ed418aead7d494e8d3c31ecd6e2743f1 (patch) | |
tree | b6ace176336e9206da6c0fd3ca7e1fe741687dad /include | |
parent | 5a0cf3251580bd3ac57c5638be73edd4244a1210 (diff) |
Optimize framing a little
- rely on the fact that data-to-come holds a reference to
data-being-written, so there's no need to add a ref for every frame
written
- provide an 'inlined' version of grpc_slice_malloc (via a #define) that
gives the compiler more information about small allocations to enable
better optimization
Diffstat (limited to 'include')
-rw-r--r-- | include/grpc/slice.h | 10 | ||||
-rw-r--r-- | include/grpc/slice_buffer.h | 4 |
2 files changed, 14 insertions, 0 deletions
diff --git a/include/grpc/slice.h b/include/grpc/slice.h index ea66e094e9..4dce6da915 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -75,6 +75,13 @@ GPRAPI grpc_slice grpc_slice_new_with_len(void *p, size_t len, call. Aborts if malloc() fails. */ GPRAPI grpc_slice grpc_slice_malloc(size_t length); +GPRAPI grpc_slice grpc_slice_malloc_large(size_t length); + +#define GRPC_SLICE_MALLOC(len) \ + ((len) <= GRPC_SLICE_INLINED_SIZE \ + ? (grpc_slice){.refcount = NULL, \ + .data.inlined = {.length = (uint8_t)(len)}} \ + : grpc_slice_malloc_large((len))) /* Intern a slice: @@ -117,6 +124,9 @@ GPRAPI grpc_slice grpc_slice_sub_no_ref(grpc_slice s, size_t begin, size_t end); Requires s intialized, split <= s.length */ GPRAPI grpc_slice grpc_slice_split_tail(grpc_slice *s, size_t split); +/* The same as grpc_slice_split_tail, but without altering refcounts */ +GPRAPI grpc_slice grpc_slice_split_tail_no_ref(grpc_slice *s, size_t split); + /* Splits s into two: modifies s to be s[split:s.length], and returns a new slice, sharing a refcount with s, that contains s[0:split]. Requires s intialized, split <= s.length */ diff --git a/include/grpc/slice_buffer.h b/include/grpc/slice_buffer.h index 2ed896645b..cdbd74776c 100644 --- a/include/grpc/slice_buffer.h +++ b/include/grpc/slice_buffer.h @@ -77,6 +77,10 @@ GPRAPI void grpc_slice_buffer_trim_end(grpc_slice_buffer *src, size_t n, /* move the first n bytes of src into dst */ GPRAPI void grpc_slice_buffer_move_first(grpc_slice_buffer *src, size_t n, grpc_slice_buffer *dst); +/* move the first n bytes of src into dst without adding references */ +GPRAPI void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer *src, + size_t n, + grpc_slice_buffer *dst); /* move the first n bytes of src into dst (copying them) */ GPRAPI void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx *exec_ctx, grpc_slice_buffer *src, |