From d5f047bee04a42f40425c34061c84b39af846e1f Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 23 May 2022 19:53:19 +0200 Subject: 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!). --- src/nvim/msgpack_rpc/unpacker.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/nvim/msgpack_rpc/unpacker.h (limited to 'src/nvim/msgpack_rpc/unpacker.h') diff --git a/src/nvim/msgpack_rpc/unpacker.h b/src/nvim/msgpack_rpc/unpacker.h new file mode 100644 index 0000000000..bbd6b1ef4f --- /dev/null +++ b/src/nvim/msgpack_rpc/unpacker.h @@ -0,0 +1,40 @@ +#ifndef NVIM_MSGPACK_RPC_UNPACKER_H +#define NVIM_MSGPACK_RPC_UNPACKER_H + +#include +#include +#include + +#include "mpack/mpack_core.h" +#include "mpack/object.h" +#include "nvim/api/private/dispatch.h" +#include "nvim/api/private/helpers.h" + +typedef struct { + mpack_parser_t parser; + mpack_tokbuf_t reader; + + const char *read_ptr; + size_t read_size; + +#define MAX_EXT_LEN 9 // byte + 8-byte integer + char ext_buf[MAX_EXT_LEN]; + + int state; + MessageType type; + uint32_t request_id; + size_t method_name_len; + MsgpackRpcRequestHandler handler; + Object error; // error return + Object result; // arg list or result + Error unpack_error; +} Unpacker; + +// unrecovareble error. unpack_error should be set! +#define unpacker_closed(p) ((p)->state < 0) + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "msgpack_rpc/unpacker.h.generated.h" +#endif + +#endif // NVIM_MSGPACK_RPC_UNPACKER_H -- cgit