diff options
author | David Robillard <d@drobilla.net> | 2019-03-10 16:21:56 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-06-21 18:12:04 +0200 |
commit | 742bcbd58eda402f3a74ca5167fa7baa57a42714 (patch) | |
tree | 757a1f62cc566d73222ec86c8963a735524cab5d /src | |
parent | 42e4a4f5ab9ed3376096251cea46bcf49621faa2 (diff) | |
download | serd-742bcbd58eda402f3a74ca5167fa7baa57a42714.tar.gz serd-742bcbd58eda402f3a74ca5167fa7baa57a42714.tar.bz2 serd-742bcbd58eda402f3a74ca5167fa7baa57a42714.zip |
Simplify internal writer context API
Diffstat (limited to 'src')
-rw-r--r-- | src/writer.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/writer.c b/src/writer.c index cf86b32e..1cd0c9eb 100644 --- a/src/writer.c +++ b/src/writer.c @@ -154,13 +154,21 @@ free_context(SerdWriter* writer) return SERD_SUCCESS; } -static inline void -push_context(SerdWriter* writer, const WriteContext new_context) +static void +push_context(SerdWriter* const writer, + const ContextType type, + const SerdNode* const g, + const SerdNode* const s, + const SerdNode* const p) { WriteContext* top = (WriteContext*)serd_stack_push(&writer->anon_stack, sizeof(WriteContext)); *top = writer->context; + + const WriteContext new_context = { + type, serd_node_copy(g), serd_node_copy(s), serd_node_copy(p), false}; + writer->context = new_context; } @@ -867,32 +875,20 @@ serd_writer_write_statement(SerdWriter* writer, } if (flags & SERD_LIST_S) { - const WriteContext ctx = {CTX_LIST, - serd_node_copy(graph), - serd_node_copy(subject), - NULL, - false}; - push_context(writer, ctx); + push_context(writer, CTX_LIST, graph, subject, NULL); } if (flags & SERD_LIST_O) { - const WriteContext ctx = {CTX_LIST, - serd_node_copy(graph), - serd_node_copy(object), - NULL, - false}; - push_context(writer, ctx); + push_context(writer, CTX_LIST, graph, object, NULL); } if (flags & (SERD_ANON_S | SERD_ANON_O)) { const bool is_list = flags & (SERD_LIST_S | SERD_LIST_O); const bool is_subject = flags & SERD_ANON_S; - const WriteContext ctx = {is_list ? CTX_LIST : CTX_BLANK, - serd_node_copy(graph), - serd_node_copy(subject), - is_subject ? serd_node_copy(predicate) : NULL, - false}; - - push_context(writer, ctx); + push_context(writer, + is_list ? CTX_LIST : CTX_BLANK, + graph, + subject, + is_subject ? predicate : NULL); } else { serd_node_set(&writer->context.graph, graph); serd_node_set(&writer->context.subject, subject); |