From 955be33cead7596506cf86211da6b0e53827ef96 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 22 Jul 2021 18:35:31 -0400 Subject: Avoid dynamic allocation when fetching interned nodes This is more or less a total rewrite of SerdNodes and the underlying ZixHash to make efficient use of the new node construction API. --- include/serd/serd.h | 93 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/serd/serd.h b/include/serd/serd.h index f67752a5..77986150 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -1223,25 +1223,33 @@ serd_nodes_intern(SerdNodes* SERD_NONNULL nodes, const SerdNode* SERD_NULLABLE node); /** - Manage `node`. + Make a string node. + + A new node will be added if an equivalent node is not already in the set. +*/ +SERD_API +const SerdNode* SERD_ALLOCATED +serd_nodes_string(SerdNodes* SERD_NONNULL nodes, SerdStringView string); - Like `serd_nodes_intern`, but takes ownership of `node`, freeing it and - returning a previously interned/managed equivalent node if necessary. +/** + Make a URI node from a string. - @return A node that is equivalent to `node`. + A new node will be constructed with serd_node_construct_token() if an + equivalent one is not already in the set. */ SERD_API const SerdNode* SERD_ALLOCATED -serd_nodes_manage(SerdNodes* SERD_NONNULL nodes, SerdNode* SERD_NULLABLE node); +serd_nodes_uri(SerdNodes* SERD_NONNULL nodes, SerdStringView string); /** - Make a string node. + Make a URI node from a parsed URI. - A new node will be added if an equivalent node is not already in the set. + A new node will be constructed with serd_node_construct_uri() if an + equivalent one is not already in the set. */ SERD_API const SerdNode* SERD_ALLOCATED -serd_nodes_string(SerdNodes* SERD_NONNULL nodes, SerdStringView string); +serd_nodes_parsed_uri(SerdNodes* SERD_NONNULL nodes, SerdURIView uri); /** Make a literal node with optional datatype or language. @@ -1273,18 +1281,75 @@ serd_nodes_literal(SerdNodes* SERD_NONNULL nodes, SerdStringView meta); /** - Make a URI node. + Make a canonical xsd:boolean node. - A new node will be added if an equivalent node is not already in the set. + A new node will be constructed with serd_node_construct_boolean() if an + equivalent one is not already in the set. */ SERD_API const SerdNode* SERD_ALLOCATED -serd_nodes_uri(SerdNodes* SERD_NONNULL nodes, SerdStringView string); +serd_nodes_boolean(SerdNodes* SERD_NONNULL nodes, bool value); + +/** + Make a canonical xsd:decimal node. + + A new node will be constructed with serd_node_construct_decimal() if an + equivalent one is not already in the set. +*/ +SERD_API +const SerdNode* SERD_ALLOCATED +serd_nodes_decimal(SerdNodes* SERD_NONNULL nodes, double value); + +/** + Make a canonical xsd:double node. + + A new node will be constructed with serd_node_construct_double() if an + equivalent one is not already in the set. +*/ +SERD_API +const SerdNode* SERD_ALLOCATED +serd_nodes_double(SerdNodes* SERD_NONNULL nodes, double value); + +/** + Make a canonical xsd:float node. + + A new node will be constructed with serd_node_construct_float() if an + equivalent one is not already in the set. +*/ +SERD_API +const SerdNode* SERD_ALLOCATED +serd_nodes_float(SerdNodes* SERD_NONNULL nodes, float value); + +/** + Make a canonical xsd:integer node. + + A new node will be constructed with serd_node_construct_integer() if an + equivalent one is not already in the set. +*/ +SERD_API +const SerdNode* SERD_ALLOCATED +serd_nodes_integer(SerdNodes* SERD_NONNULL nodes, + int64_t value, + SerdStringView datatype); + +/** + Make a canonical xsd:base64Binary node. + + A new node will be constructed with serd_node_construct_base64() if an + equivalent one is not already in the set. +*/ +SERD_API +const SerdNode* SERD_ALLOCATED +serd_nodes_base64(SerdNodes* SERD_NONNULL nodes, + const void* SERD_NONNULL value, + size_t value_size, + SerdStringView datatype); /** Make a blank node. - A new node will be added if an equivalent node is not already in the set. + A new node will be constructed with serd_node_construct_token() if an + equivalent one is not already in the set. */ SERD_API const SerdNode* SERD_ALLOCATED @@ -1299,8 +1364,8 @@ serd_nodes_blank(SerdNodes* SERD_NONNULL nodes, SerdStringView string); */ SERD_API void -serd_nodes_deref(SerdNodes* SERD_NONNULL nodes, - const SerdNode* SERD_NONNULL node); +serd_nodes_deref(SerdNodes* SERD_NONNULL nodes, + const SerdNode* SERD_NULLABLE node); /** @} -- cgit v1.2.1