aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-03-10 16:21:56 +0100
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:58 +0100
commit5e8e744c7bbc7ce9dafd1196a4c30767de5eec16 (patch)
treeceabfd0a3bf5f306a5e9a223482651682cae3718
parent66386fd801be86a8df5ae1652390c5bf8ba3132d (diff)
downloadserd-5e8e744c7bbc7ce9dafd1196a4c30767de5eec16.tar.gz
serd-5e8e744c7bbc7ce9dafd1196a4c30767de5eec16.tar.bz2
serd-5e8e744c7bbc7ce9dafd1196a4c30767de5eec16.zip
Simplify internal writer context API
-rw-r--r--src/writer.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/writer.c b/src/writer.c
index 09470b1a..fa15a47a 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -155,13 +155,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;
}
@@ -868,32 +876,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);