diff options
author | David Robillard <d@drobilla.net> | 2021-07-23 12:21:57 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-14 19:37:51 -0500 |
commit | 34852e8faa380f12b11522cfa998df4f260e3856 (patch) | |
tree | 4aff80f3b67eb29ea827f7eb02bb027d3c9fb323 /src | |
parent | 1f783d27991dabb3b8312db8970cd1778a6ae3e6 (diff) | |
download | serd-34852e8faa380f12b11522cfa998df4f260e3856.tar.gz serd-34852e8faa380f12b11522cfa998df4f260e3856.tar.bz2 serd-34852e8faa380f12b11522cfa998df4f260e3856.zip |
Avoid dynamic allocation of world blank node
Diffstat (limited to 'src')
-rw-r--r-- | src/world.c | 14 | ||||
-rw-r--r-- | src/world.h | 10 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/world.c b/src/world.c index 5af8c3d4..58efac90 100644 --- a/src/world.c +++ b/src/world.c @@ -79,6 +79,7 @@ serd_world_new(void) const SerdStringView xsd_decimal = SERD_STRING(NS_XSD "decimal"); const SerdStringView xsd_integer = SERD_STRING(NS_XSD "integer"); + world->nodes = nodes; world->rdf_first = serd_nodes_uri(nodes, rdf_first); world->rdf_nil = serd_nodes_uri(nodes, rdf_nil); world->rdf_rest = serd_nodes_uri(nodes, rdf_rest); @@ -87,8 +88,10 @@ serd_world_new(void) world->xsd_decimal = serd_nodes_uri(nodes, xsd_decimal); world->xsd_integer = serd_nodes_uri(nodes, xsd_integer); - world->blank_node = serd_new_token(SERD_BLANK, SERD_STRING("b00000000000")); - world->nodes = nodes; + serd_node_construct_token(sizeof(world->blank), + &world->blank, + SERD_BLANK, + SERD_STRING("b00000000000")); world->stderr_color = terminal_supports_color(stderr); @@ -99,7 +102,6 @@ void serd_world_free(SerdWorld* const world) { if (world) { - serd_node_free(world->blank_node); serd_nodes_free(world->nodes); free(world); } @@ -114,11 +116,11 @@ serd_world_nodes(SerdWorld* const world) const SerdNode* serd_world_get_blank(SerdWorld* const world) { - char* buf = serd_node_buffer(world->blank_node); + char* buf = world->blank.string; memset(buf, 0, BLANK_CHARS + 1); - world->blank_node->length = + world->blank.node.length = (size_t)snprintf(buf, BLANK_CHARS + 1, "b%u", ++world->next_blank_id); - return world->blank_node; + return &world->blank.node; } diff --git a/src/world.h b/src/world.h index 8043663e..8cc99e61 100644 --- a/src/world.h +++ b/src/world.h @@ -17,6 +17,7 @@ #ifndef SERD_WORLD_H #define SERD_WORLD_H +#include "node.h" #include "serd/serd.h" #include <stdbool.h> @@ -26,7 +27,6 @@ struct SerdWorldImpl { SerdNodes* nodes; SerdLogFunc log_func; void* log_handle; - SerdNode* blank_node; const SerdNode* rdf_first; const SerdNode* rdf_nil; const SerdNode* rdf_rest; @@ -34,7 +34,13 @@ struct SerdWorldImpl { const SerdNode* xsd_boolean; const SerdNode* xsd_decimal; const SerdNode* xsd_integer; - uint32_t next_blank_id; + + struct { + SerdNode node; + char string[16]; + } blank; + + uint32_t next_blank_id; bool stderr_color; }; |