diff options
author | David Robillard <d@drobilla.net> | 2021-08-08 14:15:26 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-28 21:57:07 -0500 |
commit | b0c6047765944609d1eec479898547d792419f39 (patch) | |
tree | a01836825cc5416b3eaf4c17e298dda6a2d8ce8d /src | |
parent | c6124f291118ae8270da43560d84dc5903118400 (diff) | |
download | serd-b0c6047765944609d1eec479898547d792419f39.tar.gz serd-b0c6047765944609d1eec479898547d792419f39.tar.bz2 serd-b0c6047765944609d1eec479898547d792419f39.zip |
Factor out duplicated ByteSource buffer allocation code
Diffstat (limited to 'src')
-rw-r--r-- | src/byte_source.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/byte_source.c b/src/byte_source.c index c0cb6413..567beee8 100644 --- a/src/byte_source.c +++ b/src/byte_source.c @@ -60,6 +60,18 @@ serd_byte_source_page(SerdByteSource* const source) return SERD_SUCCESS; } +static void +serd_byte_source_init_buffer(SerdByteSource* const source) +{ + if (source->page_size > 1) { + source->file_buf = (uint8_t*)serd_allocate_buffer(source->page_size); + source->read_buf = source->file_buf; + memset(source->file_buf, '\0', source->page_size); + } else { + source->read_buf = &source->read_byte; + } +} + SerdByteSource* serd_byte_source_new_function(const SerdReadFunc read_func, const SerdStreamErrorFunc error_func, @@ -92,13 +104,7 @@ serd_byte_source_new_function(const SerdReadFunc read_func, source->caret.line = 1u; source->caret.col = 1u; - if (page_size > 1) { - source->file_buf = (uint8_t*)serd_allocate_buffer(page_size); - source->read_buf = source->file_buf; - memset(source->file_buf, '\0', page_size); - } else { - source->read_buf = &source->read_byte; - } + serd_byte_source_init_buffer(source); return source; } @@ -145,13 +151,7 @@ serd_byte_source_new_filename(const char* const path, const size_t page_size) source->caret.line = 1u; source->caret.col = 1u; - if (page_size > 1) { - source->file_buf = (uint8_t*)serd_allocate_buffer(page_size); - source->read_buf = source->file_buf; - memset(source->file_buf, '\0', page_size); - } else { - source->read_buf = &source->read_byte; - } + serd_byte_source_init_buffer(source); #if USE_POSIX_FADVISE && USE_FILENO posix_fadvise(fileno(fd), 0, 0, POSIX_FADV_SEQUENTIAL); |