diff options
author | bfredl <bjorn.linse@gmail.com> | 2024-05-31 14:40:53 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2024-06-08 12:50:17 +0200 |
commit | 78d21593a35cf89692224f1000a04d3c9fff8add (patch) | |
tree | 116e12a3c41b1bd7a5e0f635b4ef0b75cf75ad9a /src/nvim/rbuffer.h | |
parent | 4881211097aba7f5d17700362ec0967e3024f074 (diff) | |
download | rneovim-78d21593a35cf89692224f1000a04d3c9fff8add.tar.gz rneovim-78d21593a35cf89692224f1000a04d3c9fff8add.tar.bz2 rneovim-78d21593a35cf89692224f1000a04d3c9fff8add.zip |
refactor(io): make rstream use a linear buffer
If you like it you shouldn't put a ring on it.
This is what _every_ consumer of RStream used anyway, either by calling
rbuffer_reset, or rbuffer_consumed_compact (same as rbuffer_reset
without needing a scratch buffer), or by consuming everything in
each stream_read_cb call directly.
Diffstat (limited to 'src/nvim/rbuffer.h')
-rw-r--r-- | src/nvim/rbuffer.h | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/src/nvim/rbuffer.h b/src/nvim/rbuffer.h deleted file mode 100644 index 942e1f2365..0000000000 --- a/src/nvim/rbuffer.h +++ /dev/null @@ -1,71 +0,0 @@ -// Specialized ring buffer. This is basically an array that wraps read/write -// pointers around the memory region. It should be more efficient than the old -// RBuffer which required memmove() calls to relocate read/write positions. -// -// The main purpose of RBuffer is simplify memory management when reading from -// uv_stream_t instances: -// -// - The event loop writes data to a RBuffer, advancing the write pointer -// - The main loop reads data, advancing the read pointer -// - If the buffer becomes full(size == capacity) the rstream is temporarily -// stopped(automatic backpressure handling) -// -// Reference: http://en.wikipedia.org/wiki/Circular_buffer -#pragma once - -#include <stddef.h> -#include <stdint.h> - -#include "nvim/rbuffer_defs.h" // IWYU pragma: keep - -// Macros that simplify working with the read/write pointers directly by hiding -// ring buffer wrap logic. Some examples: -// -// - Pass the write pointer to a function(write_data) that incrementally -// produces data, returning the number of bytes actually written to the -// ring buffer: -// -// RBUFFER_UNTIL_FULL(rbuf, ptr, cnt) -// rbuffer_produced(rbuf, write_data(state, ptr, cnt)); -// -// - Pass the read pointer to a function(read_data) that incrementally -// consumes data, returning the number of bytes actually read from the -// ring buffer: -// -// RBUFFER_UNTIL_EMPTY(rbuf, ptr, cnt) -// rbuffer_consumed(rbuf, read_data(state, ptr, cnt)); -// -// Note that the rbuffer_{produced,consumed} calls are necessary or these macros -// create infinite loops -#define RBUFFER_UNTIL_EMPTY(buf, rptr, rcnt) \ - for (size_t rcnt = 0, _r = 1; _r; _r = 0) \ - for (char *rptr = rbuffer_read_ptr(buf, &rcnt); \ - buf->size; \ - rptr = rbuffer_read_ptr(buf, &rcnt)) - -#define RBUFFER_UNTIL_FULL(buf, wptr, wcnt) \ - for (size_t wcnt = 0, _r = 1; _r; _r = 0) \ - for (char *wptr = rbuffer_write_ptr(buf, &wcnt); \ - rbuffer_space(buf); \ - wptr = rbuffer_write_ptr(buf, &wcnt)) - -// Iteration -#define RBUFFER_EACH(buf, c, i) \ - for (size_t i = 0; \ - i < buf->size; \ - i = buf->size) \ - for (char c = 0; \ - i < buf->size ? ((int)(c = *rbuffer_get(buf, i))) || 1 : 0; \ - i++) - -#define RBUFFER_EACH_REVERSE(buf, c, i) \ - for (size_t i = buf->size; \ - i != SIZE_MAX; \ - i = SIZE_MAX) \ - for (char c = 0; \ - i-- > 0 ? ((int)(c = *rbuffer_get(buf, i))) || 1 : 0; \ - ) - -#ifdef INCLUDE_GENERATED_DECLARATIONS -# include "rbuffer.h.generated.h" -#endif |