Initialize a stack with the given initial capacity, allocated from the * context's traversal scratch. Taking the context rather than an arena is * deliberate: it makes handing over ctx->arena, or a local alias of it, a type * error rather than a retention bug nobody notices. A context built without a * scratch falls back to ctx->arena, which is the behaviour that shipped before * #1997, so no
| 41 | * scratch falls back to ctx->arena, which is the behaviour that shipped before |
| 42 | * #1997, so no caller ever gets a NULL arena and silently loses nodes. */ |
| 43 | static inline void ts_nstack_init(TSNodeStack *s, const CBMExtractCtx *ctx, int initial_cap) { |
| 44 | CBMArena *arena = ctx->scratch ? ctx->scratch : ctx->arena; |
| 45 | s->scratch = arena; |
| 46 | s->items = (TSNode *)cbm_arena_alloc(arena, (size_t)initial_cap * sizeof(TSNode)); |
| 47 | s->count = 0; |
| 48 | s->cap = s->items ? initial_cap : 0; |
| 49 | } |
| 50 | |
| 51 | /* Push a node onto the stack, growing 2x if needed. */ |
| 52 | static inline void ts_nstack_push(TSNodeStack *s, TSNode node) { |
no test coverage detected