aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2015-06-30 13:37:19 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2015-07-01 05:40:53 -0300
commit0ef80b9c2b922280c3ba2c0a8638f23ae57d6618 (patch)
treec8d6f5631df1e8eb69022cae647f6e0436254830 /src/nvim/eval.c
parentdcaf9c6bc3d5f83782fca7a145ba5feac7746b1e (diff)
downloadrneovim-0ef80b9c2b922280c3ba2c0a8638f23ae57d6618.tar.gz
rneovim-0ef80b9c2b922280c3ba2c0a8638f23ae57d6618.tar.bz2
rneovim-0ef80b9c2b922280c3ba2c0a8638f23ae57d6618.zip
rbuffer: Reimplement as a ring buffer and decouple from rstream
Extract the RBuffer class from rstream.c and reimplement it as a ring buffer, a more efficient version that doesn't need to relocate memory. The old rbuffer_read/rbuffer_write interfaces are kept for simple reading/writing, and the RBUFFER_UNTIL_{FULL,EMPTY} macros are introduced to hide wrapping logic when more control is required(such as passing the buffer pointer to a library function that writes directly to the pointer) Also add a basic infrastructure for writing helper C files that are only compiled in the unit test library, and use this to write unit tests for RBuffer which contains some macros that can't be accessed directly by luajit. Helped-by: oni-link <knil.ino@gmail.com> Reviewed-by: oni-link <knil.ino@gmail.com> Reviewed-by: Scott Prager <splinterofchaos@gmail.com> Reviewed-by: Justin M. Keyes <justinkz@gmail.com> Reviewed-by: Michael Reed <m.reed@mykolab.com>
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 93590445c9..d3ab47a505 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -20341,19 +20341,19 @@ static inline void push_job_event(Job *job, ufunc_T *callback,
}, !disable_job_defer);
}
-static void on_job_stdout(RStream *rstream, void *job, bool eof)
+static void on_job_stdout(RStream *rstream, RBuffer *buf, void *job, bool eof)
{
TerminalJobData *data = job_data(job);
- on_job_output(rstream, job, eof, data->on_stdout, "stdout");
+ on_job_output(rstream, job, buf, eof, data->on_stdout, "stdout");
}
-static void on_job_stderr(RStream *rstream, void *job, bool eof)
+static void on_job_stderr(RStream *rstream, RBuffer *buf, void *job, bool eof)
{
TerminalJobData *data = job_data(job);
- on_job_output(rstream, job, eof, data->on_stderr, "stderr");
+ on_job_output(rstream, job, buf, eof, data->on_stderr, "stderr");
}
-static void on_job_output(RStream *rstream, Job *job, bool eof,
+static void on_job_output(RStream *rstream, Job *job, RBuffer *buf, bool eof,
ufunc_T *callback, const char *type)
{
if (eof) {
@@ -20361,20 +20361,19 @@ static void on_job_output(RStream *rstream, Job *job, bool eof,
}
TerminalJobData *data = job_data(job);
- char *ptr = rstream_read_ptr(rstream);
- size_t len = rstream_pending(rstream);
+ RBUFFER_UNTIL_EMPTY(buf, ptr, len) {
+ // The order here matters, the terminal must receive the data first because
+ // push_job_event will modify the read buffer(convert NULs into NLs)
+ if (data->term) {
+ terminal_receive(data->term, ptr, len);
+ }
- // The order here matters, the terminal must receive the data first because
- // push_job_event will modify the read buffer(convert NULs into NLs)
- if (data->term) {
- terminal_receive(data->term, ptr, len);
- }
+ if (callback) {
+ push_job_event(job, callback, type, ptr, len, 0);
+ }
- if (callback) {
- push_job_event(job, callback, type, ptr, len, 0);
+ rbuffer_consumed(buf, len);
}
-
- rbuffer_consumed(rstream_buffer(rstream), len);
}
static void on_job_exit(Job *job, int status, void *d)