summaryrefslogtreecommitdiff
path: root/prism/internal/node.h
blob: ca6d5616d76ee53520f67c72572564a3f690cea4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef PRISM_INTERNAL_NODE_H
#define PRISM_INTERNAL_NODE_H

#include "prism/node.h"

#include "prism/compiler/force_inline.h"

#include "prism/arena.h"

/*
 * Slow path for pm_node_list_append: grow the list and append the node.
 * Do not call directly — use pm_node_list_append instead.
 */
void pm_node_list_append_slow(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);

/* Append a new node onto the end of the node list. */
static PRISM_FORCE_INLINE void
pm_node_list_append(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node) {
    if (list->size < list->capacity) {
        list->nodes[list->size++] = node;
    } else {
        pm_node_list_append_slow(arena, list, node);
    }
}

/* Prepend a new node onto the beginning of the node list. */
void pm_node_list_prepend(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);

/* Concatenate the given node list onto the end of the other node list. */
void pm_node_list_concat(pm_arena_t *arena, pm_node_list_t *list, pm_node_list_t *other);

#endif