diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-10-01 15:37:20 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-10-01 15:37:20 -0300 |
commit | 536c0ba27e79929eb30850d8e11f2ed026930ab3 (patch) | |
tree | 40873cf933b5ba5cff44d1ea07db2b3f2663020e /src/nvim/rbuffer.c | |
parent | afe8a32be01d006d6c25f69b4aa1b6e92464ab63 (diff) | |
parent | 5d185c77726dfff20b87d97897d2bb237e95d95a (diff) | |
download | rneovim-536c0ba27e79929eb30850d8e11f2ed026930ab3.tar.gz rneovim-536c0ba27e79929eb30850d8e11f2ed026930ab3.tar.bz2 rneovim-536c0ba27e79929eb30850d8e11f2ed026930ab3.zip |
Merge PR #3360 'More fixes for 0.1'
Diffstat (limited to 'src/nvim/rbuffer.c')
-rw-r--r-- | src/nvim/rbuffer.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/nvim/rbuffer.c b/src/nvim/rbuffer.c index 0a04ba1954..b3805a3a28 100644 --- a/src/nvim/rbuffer.c +++ b/src/nvim/rbuffer.c @@ -24,11 +24,13 @@ RBuffer *rbuffer_new(size_t capacity) rv->size = 0; rv->write_ptr = rv->read_ptr = rv->start_ptr; rv->end_ptr = rv->start_ptr + capacity; + rv->temp = NULL; return rv; } void rbuffer_free(RBuffer *buf) { + xfree(buf->temp); xfree(buf); } @@ -69,12 +71,20 @@ char *rbuffer_write_ptr(RBuffer *buf, size_t *write_count) FUNC_ATTR_NONNULL_ALL return buf->write_ptr; } -// Set read and write pointer for an empty RBuffer to the beginning of the -// buffer. +// Reset an RBuffer so read_ptr is at the beginning of the memory. If +// necessary, this moves existing data by allocating temporary memory. void rbuffer_reset(RBuffer *buf) FUNC_ATTR_NONNULL_ALL { - if (buf->size == 0) { - buf->write_ptr = buf->read_ptr = buf->start_ptr; + size_t temp_size; + if ((temp_size = rbuffer_size(buf))) { + if (buf->temp == NULL) { + buf->temp = xmalloc(rbuffer_capacity(buf)); + } + rbuffer_read(buf, buf->temp, buf->size); + } + buf->read_ptr = buf->write_ptr = buf->start_ptr; + if (temp_size) { + rbuffer_write(buf, buf->temp, temp_size); } } |