aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/rbuffer.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-05-23 19:53:19 +0200
committerbfredl <bjorn.linse@gmail.com>2022-06-02 16:05:24 +0200
commitd5f047bee04a42f40425c34061c84b39af846e1f (patch)
treed81bb803389467604e2ad319b54b211415594ce6 /src/nvim/rbuffer.c
parentd93ba03c717bee05fe6d239fd7faefe6e9698c85 (diff)
downloadrneovim-d5f047bee04a42f40425c34061c84b39af846e1f.tar.gz
rneovim-d5f047bee04a42f40425c34061c84b39af846e1f.tar.bz2
rneovim-d5f047bee04a42f40425c34061c84b39af846e1f.zip
refactor(api): use a unpacker based on libmpack instead of msgpack-c
Currently this is more or less a straight off reimplementation, but this allow further optimizations down the line, especially for avoiding memory allocations of rpc objects. Current score for "make functionaltest; make oldtest" on a -DEXITFREE build: is 117 055 352 xfree(ptr != NULL) calls (that's NUMBERWANG!).
Diffstat (limited to 'src/nvim/rbuffer.c')
-rw-r--r--src/nvim/rbuffer.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/nvim/rbuffer.c b/src/nvim/rbuffer.c
index d280e08c03..6407ac172e 100644
--- a/src/nvim/rbuffer.c
+++ b/src/nvim/rbuffer.c
@@ -154,6 +154,23 @@ void rbuffer_consumed(RBuffer *buf, size_t count)
}
}
+/// Use instead of rbuffer_consumed to use rbuffer in a linear, non-cyclic fashion.
+///
+/// This is generally usefull if we can guarantee to parse all input
+/// except some small incomplete token, like when parsing msgpack.
+void rbuffer_consumed_compact(RBuffer *buf, size_t count)
+ FUNC_ATTR_NONNULL_ALL
+{
+ assert(buf->read_ptr <= buf->write_ptr);
+ rbuffer_consumed(buf, count);
+ if (buf->read_ptr > buf->start_ptr) {
+ assert((size_t)(buf->read_ptr - buf->write_ptr) == buf->size);
+ memmove(buf->start_ptr, buf->read_ptr, buf->size);
+ buf->read_ptr = buf->start_ptr;
+ buf->write_ptr = buf->read_ptr + buf->size;
+ }
+}
+
// Higher level functions for copying from/to RBuffer instances and data
// pointers
size_t rbuffer_write(RBuffer *buf, const char *src, size_t src_size)