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. --- src/node_spec.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/node_spec.h (limited to 'src/node_spec.h') diff --git a/src/node_spec.h b/src/node_spec.h new file mode 100644 index 00000000..fcf19712 --- /dev/null +++ b/src/node_spec.h @@ -0,0 +1,53 @@ +/* + Copyright 2021 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef SERD_NODE_SPEC_H +#define SERD_NODE_SPEC_H + +#include "serd/serd.h" + +/** + A lightweight "specification" of a node. + + This is essentially the arguments needed to construct any node combined into + a single structure. Since it only refers to strings elsewhere, it is + convenient as a way to completely specify a node without having to actually + allocate one. +*/ +typedef struct { + SerdNodeType type; ///< Basic type of this node + SerdStringView string; ///< String contents of this node + SerdNodeFlags flags; ///< Additional node flags + SerdStringView meta; ///< String contents of datatype or language node +} NodeSpec; + +static inline NodeSpec +token_spec(const SerdNodeType type, const SerdStringView string) +{ + NodeSpec spec = {type, string, 0u, SERD_EMPTY_STRING()}; + return spec; +} + +static inline NodeSpec +literal_spec(const SerdStringView string, + const SerdNodeFlags flags, + const SerdStringView meta) +{ + NodeSpec spec = {SERD_LITERAL, string, flags, meta}; + return spec; +} + +#endif // SERD_NODE_SPEC_H -- cgit v1.2.1