summaryrefslogtreecommitdiff
path: root/include/parserutils/utils/buffer.h
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2021-05-16 14:35:30 +0100
committerMichael Drake <michael.drake@codethink.co.uk>2021-05-16 14:35:30 +0100
commitd101b2bb6dc98050f8f1b04d9d2bfeeff5a120c7 (patch)
treee62cf6cacc4b33a40672b8e1696817a16144c997 /include/parserutils/utils/buffer.h
parent269b0047aa506be93637e93d109a34f4bd7cefc4 (diff)
downloadlibparserutils-d101b2bb6dc98050f8f1b04d9d2bfeeff5a120c7.tar.gz
libparserutils-d101b2bb6dc98050f8f1b04d9d2bfeeff5a120c7.tar.bz2
Buffer: Optimise to minimise memmove shuffles.
Previously the data in the linear buffer was always stored at the start of the allocation, pointed to by `buffer->data`. This was achieved by memmoving every time data was consumed from the front. Now the allocation is pointed to by `buffer->alloc`, and the start of the data is pointed to by `buffer->data` (as before). This means client code does not need to change to get at the data. The advantage comes when we discard the from the start of the buffer, when some data is consumed. We now simply advance the data pointer by the number of bytes to be discarded, and reduce the buffer length by the same amount. If the used portion of the buffer now fits between the start of the allocation and the current start of the data, it is memcpyed to the allocation start, otherwise it is left alone. This is a significant optimisation when the size of the chunk is large, such as when loading from disc. (When the first (only) "chunk" is just the whole file.
Diffstat (limited to 'include/parserutils/utils/buffer.h')
-rw-r--r--include/parserutils/utils/buffer.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/parserutils/utils/buffer.h b/include/parserutils/utils/buffer.h
index 9425070..5f8f696 100644
--- a/include/parserutils/utils/buffer.h
+++ b/include/parserutils/utils/buffer.h
@@ -18,6 +18,7 @@ extern "C"
struct parserutils_buffer
{
+ uint8_t *alloc;
uint8_t *data;
size_t length;
size_t allocated;