aboutsummaryrefslogtreecommitdiffstats
path: root/src/nodes.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-12-19 17:55:02 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commit0f9816d67bc67a396607291f845ca2a33c2285a7 (patch)
treeb31fd1b344305dc984a2109084fa183573a0ae43 /src/nodes.c
parent258ea2ff59bbd2127ea446cf4b9676ad3d7fe53d (diff)
downloadserd-0f9816d67bc67a396607291f845ca2a33c2285a7.tar.gz
serd-0f9816d67bc67a396607291f845ca2a33c2285a7.tar.bz2
serd-0f9816d67bc67a396607291f845ca2a33c2285a7.zip
Use ZixAllocator directly
Diffstat (limited to 'src/nodes.c')
-rw-r--r--src/nodes.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/nodes.c b/src/nodes.c
index 22ee3146..e353b9aa 100644
--- a/src/nodes.c
+++ b/src/nodes.c
@@ -3,7 +3,6 @@
#include "nodes.h"
-#include "memory.h"
#include "node.h"
#include "node_spec.h"
@@ -12,7 +11,6 @@
#define ZIX_HASH_RECORD_TYPE NodesEntry
#define ZIX_HASH_SEARCH_DATA_TYPE NodeSpec
-#include "serd/memory.h"
#include "serd/nodes.h"
#include "serd/write_result.h"
#include "zix/allocator.h"
@@ -76,16 +74,16 @@ typedef struct {
with an extra header) rather than node pointers directly.
*/
typedef struct {
- SerdAllocator base; ///< Implementation of SerdAllocator (base "class")
- SerdAllocator* real; ///< Underlying "real" memory allocator
+ ZixAllocator base; ///< Implementation of ZixAllocator (base "class")
+ ZixAllocator* real; ///< Underlying "real" memory allocator
} SerdNodesEntryAllocator;
ZIX_MALLOC_FUNC static void*
-serd_nodes_entry_aligned_alloc(SerdAllocator* const allocator,
- const size_t alignment,
- const size_t size)
+serd_nodes_entry_aligned_alloc(ZixAllocator* const allocator,
+ const size_t alignment,
+ const size_t size)
{
- SerdAllocator* const real = ((SerdNodesEntryAllocator*)allocator)->real;
+ ZixAllocator* const real = ((SerdNodesEntryAllocator*)allocator)->real;
void* const ptr =
real->aligned_alloc(real, alignment, serd_node_align + size);
@@ -94,9 +92,9 @@ serd_nodes_entry_aligned_alloc(SerdAllocator* const allocator,
}
static void
-serd_nodes_entry_aligned_free(SerdAllocator* const allocator, void* const ptr)
+serd_nodes_entry_aligned_free(ZixAllocator* const allocator, void* const ptr)
{
- SerdAllocator* const real = ((SerdNodesEntryAllocator*)allocator)->real;
+ ZixAllocator* const real = ((SerdNodesEntryAllocator*)allocator)->real;
if (ptr) {
real->aligned_free(real, (((uint8_t*)ptr) - serd_node_align));
@@ -104,7 +102,7 @@ serd_nodes_entry_aligned_free(SerdAllocator* const allocator, void* const ptr)
}
static SerdNodesEntryAllocator
-serd_nodes_entry_allocator(SerdAllocator* const real)
+serd_nodes_entry_allocator(ZixAllocator* const real)
{
const SerdNodesEntryAllocator entry_allocator = {
{
@@ -115,7 +113,7 @@ serd_nodes_entry_allocator(SerdAllocator* const real)
serd_nodes_entry_aligned_alloc,
serd_nodes_entry_aligned_free,
},
- real ? real : serd_default_allocator(),
+ real ? real : zix_default_allocator(),
};
return entry_allocator;
@@ -228,21 +226,21 @@ nodes_equal(const SerdNode* const a, const SerdNode* const b)
static void
free_entry(SerdNodes* const nodes, NodesEntry* const entry)
{
- serd_aaligned_free(&nodes->allocator.base, &entry->node);
+ zix_aligned_free(&nodes->allocator.base, &entry->node);
}
SerdNodes*
-serd_nodes_new(SerdAllocator* const allocator)
+serd_nodes_new(ZixAllocator* const allocator)
{
SerdNodes* const nodes =
- (SerdNodes*)serd_acalloc(allocator, 1, sizeof(SerdNodes));
+ (SerdNodes*)zix_calloc(allocator, 1, sizeof(SerdNodes));
if (nodes) {
nodes->allocator = serd_nodes_entry_allocator(allocator);
- if (!(nodes->hash = zix_hash_new(
- (ZixAllocator*)allocator, nodes_key, nodes_hash, nodes_equal))) {
- serd_afree(allocator, nodes);
+ if (!(nodes->hash =
+ zix_hash_new(allocator, nodes_key, nodes_hash, nodes_equal))) {
+ zix_free(allocator, nodes);
return NULL;
}
}
@@ -261,7 +259,7 @@ serd_nodes_free(SerdNodes* nodes)
}
zix_hash_free(nodes->hash);
- serd_afree(nodes->allocator.real, nodes);
+ zix_free(nodes->allocator.real, nodes);
}
}
@@ -399,8 +397,8 @@ serd_nodes_token(SerdNodes* const nodes,
}
// Otherwise, allocate and manage a new one
- SerdAllocator* const alloc = &nodes->allocator.base;
- SerdNode* const node = serd_node_new(alloc, serd_a_token(type, string));
+ ZixAllocator* const alloc = &nodes->allocator.base;
+ SerdNode* const node = serd_node_new(alloc, serd_a_token(type, string));
return serd_nodes_manage_entry_node_at(nodes, node, plan);
}
@@ -428,8 +426,8 @@ serd_nodes_literal(SerdNodes* const nodes,
}
// Otherwise, allocate and manage a new one
- SerdAllocator* const alloc = &nodes->allocator.base;
- SerdNode* const node =
+ ZixAllocator* const alloc = &nodes->allocator.base;
+ SerdNode* const node =
serd_node_new(alloc, serd_a_literal(string, flags, meta));
return serd_nodes_manage_entry_node_at(nodes, node, plan);