Realloc parse stack when it grows to its capacity
This commit is contained in:
parent
3ea9f709a4
commit
e6bbab41e5
2 changed files with 6 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ static TSStateId INITIAL_STATE = 0;
|
|||
TSStack ts_stack_make() {
|
||||
TSStack result = {
|
||||
.entries = calloc(INITIAL_STACK_SIZE, sizeof(*result.entries)), .size = 0,
|
||||
.capacity = INITIAL_STACK_SIZE,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
|
@ -30,6 +31,10 @@ TSTree *ts_stack_top_node(const TSStack *stack) {
|
|||
}
|
||||
|
||||
void ts_stack_push(TSStack *stack, TSStateId state, TSTree *node) {
|
||||
if (stack->size == stack->capacity) {
|
||||
stack->capacity *= 2;
|
||||
stack->entries = realloc(stack->entries, stack->capacity * sizeof(*stack->entries));
|
||||
}
|
||||
stack->entries[stack->size].state = state;
|
||||
stack->entries[stack->size].node = node;
|
||||
stack->size++;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ extern "C" {
|
|||
|
||||
typedef struct {
|
||||
size_t size;
|
||||
size_t capacity;
|
||||
struct {
|
||||
TSTree *node;
|
||||
TSStateId state;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue