aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-07-23 12:21:57 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commitd4bfea4ad74f8a737dad143f6f136aff499cb23f (patch)
treed80433e0357fff4954aea91f99d2edb2f02c9d69
parent2019d1581c1296cc534c731a1f454ce08b460dcc (diff)
downloadserd-d4bfea4ad74f8a737dad143f6f136aff499cb23f.tar.gz
serd-d4bfea4ad74f8a737dad143f6f136aff499cb23f.tar.bz2
serd-d4bfea4ad74f8a737dad143f6f136aff499cb23f.zip
Avoid dynamic allocation of world blank node
-rw-r--r--src/world.c20
-rw-r--r--src/world.h7
2 files changed, 15 insertions, 12 deletions
diff --git a/src/world.c b/src/world.c
index c4787aba..37cfe301 100644
--- a/src/world.c
+++ b/src/world.c
@@ -23,15 +23,13 @@ serd_world_new(SerdAllocator* const allocator)
SerdAllocator* const actual =
allocator ? allocator : serd_default_allocator();
- SerdWorld* world = (SerdWorld*)serd_acalloc(actual, 1, sizeof(SerdWorld));
- SerdNode* blank_node =
- serd_node_new(actual, serd_a_blank_string("b00000000000"));
+ SerdWorld* const world =
+ (SerdWorld*)serd_acalloc(actual, 1, sizeof(SerdWorld));
SerdNodes* const nodes = serd_nodes_new(actual);
- if (!world || !blank_node || !nodes) {
+ if (!world || !nodes) {
serd_nodes_free(nodes);
- serd_node_free(actual, blank_node);
serd_afree(actual, world);
return NULL;
}
@@ -48,7 +46,6 @@ serd_world_new(SerdAllocator* const allocator)
world->limits.writer_max_depth = 128U;
world->allocator = actual;
world->nodes = nodes;
- world->blank_node = blank_node;
serd_log_init(&world->log);
@@ -60,11 +57,13 @@ serd_world_new(SerdAllocator* const allocator)
!(world->xsd_decimal = serd_nodes_get(nodes, serd_a_uri(xsd_decimal))) ||
!(world->xsd_integer = serd_nodes_get(nodes, serd_a_uri(xsd_integer)))) {
serd_nodes_free(nodes);
- serd_node_free(actual, blank_node);
serd_afree(actual, world);
return NULL;
}
+ serd_node_construct(
+ sizeof(world->blank), &world->blank, serd_a_blank_string("b00000000000"));
+
return world;
}
@@ -72,7 +71,6 @@ void
serd_world_free(SerdWorld* const world)
{
if (world) {
- serd_node_free(world->allocator, world->blank_node);
serd_nodes_free(world->nodes);
serd_afree(world->allocator, world);
}
@@ -100,13 +98,13 @@ serd_world_get_blank(SerdWorld* const world)
assert(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;
#undef BLANK_CHARS
}
diff --git a/src/world.h b/src/world.h
index 0888b480..8033dcec 100644
--- a/src/world.h
+++ b/src/world.h
@@ -5,6 +5,7 @@
#define SERD_SRC_WORLD_H
#include "log.h"
+#include "node.h"
#include "serd/memory.h"
#include "serd/node.h"
@@ -25,9 +26,13 @@ struct SerdWorldImpl {
const SerdNode* xsd_boolean;
const SerdNode* xsd_decimal;
const SerdNode* xsd_integer;
- SerdNode* blank_node;
uint32_t next_blank_id;
uint32_t next_document_id;
+
+ struct {
+ SerdNode node;
+ char string[16];
+ } blank;
};
#endif // SERD_SRC_WORLD_H