neovim/test/unit/fixtures/rbuffer.c
Thiago de Arruda 0ef80b9c2b 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>
2015-07-01 05:40:53 -03:00

29 lines
569 B
C

#include "nvim/rbuffer.h"
#include "rbuffer.h"
void ut_rbuffer_each_read_chunk(RBuffer *buf, each_ptr_cb cb)
{
RBUFFER_UNTIL_EMPTY(buf, rptr, rcnt) {
cb(rptr, rcnt);
rbuffer_consumed(buf, rcnt);
}
}
void ut_rbuffer_each_write_chunk(RBuffer *buf, each_ptr_cb cb)
{
RBUFFER_UNTIL_FULL(buf, wptr, wcnt) {
cb(wptr, wcnt);
rbuffer_produced(buf, wcnt);
}
}
void ut_rbuffer_each(RBuffer *buf, each_cb cb)
{
RBUFFER_EACH(buf, c, i) cb(c, i);
}
void ut_rbuffer_each_reverse(RBuffer *buf, each_cb cb)
{
RBUFFER_EACH_REVERSE(buf, c, i) cb(c, i);
}