aboutsummaryrefslogtreecommitdiffstats
path: root/src/byte_source.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-12-19 13:16:56 -0500
committerDavid Robillard <d@drobilla.net>2021-03-08 23:23:06 -0500
commit1307128c0a6b5cffeecfb66db0ca1763d381e782 (patch)
tree6f5b66cb03fcb3553b3b43c142d57a67928a36f1 /src/byte_source.h
parent1c1c060d7a449952051b2dd78176e48db53df1c4 (diff)
downloadserd-1307128c0a6b5cffeecfb66db0ca1763d381e782.tar.gz
serd-1307128c0a6b5cffeecfb66db0ca1763d381e782.tar.bz2
serd-1307128c0a6b5cffeecfb66db0ca1763d381e782.zip
Simplify ByteSource implementation
Diffstat (limited to 'src/byte_source.h')
-rw-r--r--src/byte_source.h25
1 files changed, 5 insertions, 20 deletions
diff --git a/src/byte_source.h b/src/byte_source.h
index db9b29af..ff281435 100644
--- a/src/byte_source.h
+++ b/src/byte_source.h
@@ -79,7 +79,8 @@ serd_byte_source_peek(SerdByteSource* source)
static inline SerdStatus
serd_byte_source_advance(SerdByteSource* source)
{
- SerdStatus st = SERD_SUCCESS;
+ SerdStatus st = SERD_SUCCESS;
+ const bool was_eof = source->eof;
switch (serd_byte_source_peek(source)) {
case '\n':
@@ -90,28 +91,12 @@ serd_byte_source_advance(SerdByteSource* source)
++source->cur.col;
}
- const bool was_eof = source->eof;
if (source->from_stream) {
- source->eof = false;
- if (source->page_size > 1) {
- if (++source->read_head == source->page_size) {
- st = serd_byte_source_page(source);
- } else if (source->read_head == source->buf_size) {
- source->eof = true;
- }
- } else {
- source->eof = false;
- if (!source->read_func(&source->read_byte, 1, 1, source->stream)) {
- source->eof = true;
- st =
- source->error_func(source->stream) ? SERD_ERR_UNKNOWN : SERD_FAILURE;
- }
+ if (++source->read_head >= source->buf_size) {
+ st = serd_byte_source_page(source);
}
} else if (!source->eof) {
- ++source->read_head; // Move to next character in string
- if (source->read_buf[source->read_head] == '\0') {
- source->eof = true;
- }
+ source->eof = source->read_buf[++source->read_head] == '\0';
}
return (was_eof && source->eof) ? SERD_FAILURE : st;