diff options
author | David Robillard <d@drobilla.net> | 2021-07-22 18:35:31 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-14 19:37:51 -0500 |
commit | 955be33cead7596506cf86211da6b0e53827ef96 (patch) | |
tree | 0dac1a7a31e8c50d1ba7200648d6ce402f97867d /src/node_spec.h | |
parent | 34852e8faa380f12b11522cfa998df4f260e3856 (diff) | |
download | serd-955be33cead7596506cf86211da6b0e53827ef96.tar.gz serd-955be33cead7596506cf86211da6b0e53827ef96.tar.bz2 serd-955be33cead7596506cf86211da6b0e53827ef96.zip |
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.
Diffstat (limited to 'src/node_spec.h')
-rw-r--r-- | src/node_spec.h | 53 |
1 files changed, 53 insertions, 0 deletions
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 <d@drobilla.net> + + 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 |