Push a node onto the stack, growing 2x if needed. */
| 31 | |
| 32 | /* Push a node onto the stack, growing 2x if needed. */ |
| 33 | static inline void ts_nstack_push(TSNodeStack *s, CBMArena *arena, TSNode node) { |
| 34 | if (s->count >= s->cap) { |
| 35 | int new_cap = s->cap ? s->cap * 2 : 512; |
| 36 | TSNode *new_items = (TSNode *)cbm_arena_alloc(arena, (size_t)new_cap * sizeof(TSNode)); |
| 37 | if (!new_items) |
| 38 | return; /* OOM: best-effort, stop growing */ |
| 39 | if (s->items && s->count > 0) { |
| 40 | memcpy(new_items, s->items, (size_t)s->count * sizeof(TSNode)); |
| 41 | } |
| 42 | /* Old s->items is abandoned in the arena — freed on arena_destroy. */ |
| 43 | s->items = new_items; |
| 44 | s->cap = new_cap; |
| 45 | } |
| 46 | s->items[s->count++] = node; |
| 47 | } |
| 48 | |
| 49 | /* Pop a node from the stack. Caller must check s->count > 0. */ |
| 50 | static inline TSNode ts_nstack_pop(TSNodeStack *s) { |
no test coverage detected