Push a node onto the stack, growing 2x if needed. */
| 50 | |
| 51 | /* Push a node onto the stack, growing 2x if needed. */ |
| 52 | static inline void ts_nstack_push(TSNodeStack *s, TSNode node) { |
| 53 | if (s->count >= s->cap) { |
| 54 | int new_cap = s->cap ? s->cap * 2 : 512; |
| 55 | TSNode *new_items = (TSNode *)cbm_arena_alloc(s->scratch, (size_t)new_cap * sizeof(TSNode)); |
| 56 | if (!new_items) |
| 57 | return; /* OOM: best-effort, stop growing */ |
| 58 | if (s->items && s->count > 0) { |
| 59 | memcpy(new_items, s->items, (size_t)s->count * sizeof(TSNode)); |
| 60 | } |
| 61 | /* Old s->items is abandoned in the arena — freed on arena_destroy. */ |
| 62 | s->items = new_items; |
| 63 | s->cap = new_cap; |
| 64 | } |
| 65 | s->items[s->count++] = node; |
| 66 | } |
| 67 | |
| 68 | /* Pop a node from the stack. Caller must check s->count > 0. */ |
| 69 | static inline TSNode ts_nstack_pop(TSNodeStack *s) { |
no test coverage detected