aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-07-22 16:57:46 +0200
committerDavid Robillard <d@drobilla.net>2018-07-22 16:57:46 +0200
commit8b8890dd104066c190497792e427ad2a9a7f918a (patch)
tree26b553712fcb6fca01fc1199f97cd7e189a31488
parentade6c7579fae302d64681555a77dbf78fcacd682 (diff)
downloadserd-8b8890dd104066c190497792e427ad2a9a7f918a.tar.gz
serd-8b8890dd104066c190497792e427ad2a9a7f918a.tar.bz2
serd-8b8890dd104066c190497792e427ad2a9a7f918a.zip
Inline serd_byte_source_advance
-rw-r--r--src/byte_source.c35
-rw-r--r--src/serd_internal.h36
2 files changed, 35 insertions, 36 deletions
diff --git a/src/byte_source.c b/src/byte_source.c
index 1b02c2be..1a67157b 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -16,7 +16,7 @@
#include "serd_internal.h"
-static inline SerdStatus
+SerdStatus
serd_byte_source_page(SerdByteSource* source)
{
source->read_head = 0;
@@ -96,36 +96,3 @@ serd_byte_source_close(SerdByteSource* source)
memset(source, '\0', sizeof(*source));
return SERD_SUCCESS;
}
-
-SerdStatus
-serd_byte_source_advance(SerdByteSource* source)
-{
- const bool paging = source->page_size > 1;
- SerdStatus st = SERD_SUCCESS;
-
- switch (serd_byte_source_peek(source)) {
- case '\0': break;
- case '\n': ++source->cur.line; source->cur.col = 0; break;
- default: ++source->cur.col;
- }
-
- // Reset EOF marker for reading from sockets/pipes
- source->eof = source->eof && !source->from_stream;
-
- if (source->from_stream && paging) {
- if (++source->read_head == source->page_size) {
- st = serd_byte_source_page(source);
- }
- } else if (source->from_stream) {
- if (!source->read_func(&source->read_byte, 1, 1, source->stream)) {
- st = source->error_func(source->stream) ? SERD_ERR_UNKNOWN
- : SERD_FAILURE;
- }
- } else if (source->eof) {
- st = SERD_FAILURE; // Can't read past end of string
- } else {
- ++source->read_head; // Move to next character in string
- }
-
- return st;
-}
diff --git a/src/serd_internal.h b/src/serd_internal.h
index 18cc74bd..fecd2b6a 100644
--- a/src/serd_internal.h
+++ b/src/serd_internal.h
@@ -118,6 +118,9 @@ serd_byte_source_close(SerdByteSource* source);
SerdStatus
serd_byte_source_prepare(SerdByteSource* source);
+SerdStatus
+serd_byte_source_page(SerdByteSource* source);
+
static inline uint8_t
serd_byte_source_peek(SerdByteSource* source)
{
@@ -125,8 +128,37 @@ serd_byte_source_peek(SerdByteSource* source)
return source->read_buf[source->read_head];
}
-SerdStatus
-serd_byte_source_advance(SerdByteSource* source);
+static inline SerdStatus
+serd_byte_source_advance(SerdByteSource* source)
+{
+ SerdStatus st = SERD_SUCCESS;
+
+ switch (serd_byte_source_peek(source)) {
+ case '\0': break;
+ case '\n': ++source->cur.line; source->cur.col = 0; break;
+ default: ++source->cur.col;
+ }
+
+ 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_func(&source->read_byte, 1, 1, source->stream)) {
+ st = source->error_func(source->stream) ? SERD_ERR_UNKNOWN
+ : SERD_FAILURE;
+ }
+ }
+ } else if (source->eof) {
+ st = SERD_FAILURE; // Can't read past end of string
+ } else {
+ ++source->read_head; // Move to next character in string
+ }
+
+ return st;
+}
/* Stack */