Move match stack to automatic storage duration.
This commit is contained in:
parent
85e40f6ceb
commit
aaf881d672
|
@ -143,7 +143,7 @@ struct ctlseqs_matcher {
|
||||||
struct ctlseqs_trie_node *node_pools[CTLSEQS_TRIE_NODE_POOL_MAX_NUM];
|
struct ctlseqs_trie_node *node_pools[CTLSEQS_TRIE_NODE_POOL_MAX_NUM];
|
||||||
size_t pool_idx;
|
size_t pool_idx;
|
||||||
size_t pool_size;
|
size_t pool_size;
|
||||||
struct ctlseqs_match_ctx *match_stack;
|
size_t match_stack_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ctlseqs_reader {
|
struct ctlseqs_reader {
|
||||||
|
@ -295,7 +295,7 @@ CTLSEQS_HOT static ssize_t
|
||||||
ctlseqs_match_pattern(struct ctlseqs_matcher const *matcher, struct ctlseqs_match_args const *args)
|
ctlseqs_match_pattern(struct ctlseqs_matcher const *matcher, struct ctlseqs_match_args const *args)
|
||||||
{
|
{
|
||||||
struct ctlseqs_trie_node const *old_node, empty_node = { 0 };
|
struct ctlseqs_trie_node const *old_node, empty_node = { 0 };
|
||||||
struct ctlseqs_match_ctx match_ctx = {
|
struct ctlseqs_match_ctx match_stack[matcher->match_stack_size], match_ctx = {
|
||||||
.node = matcher == NULL ? &empty_node : &matcher->root,
|
.node = matcher == NULL ? &empty_node : &matcher->root,
|
||||||
.seq = args->seq + 1,
|
.seq = args->seq + 1,
|
||||||
.result = args->result + (args->save_seq ? 2 : 0),
|
.result = args->result + (args->save_seq ? 2 : 0),
|
||||||
|
@ -314,7 +314,7 @@ ctlseqs_match_pattern(struct ctlseqs_matcher const *matcher, struct ctlseqs_matc
|
||||||
old_node = match_ctx.node;
|
old_node = match_ctx.node;
|
||||||
match_ctx.node = match_ctx.node->children[-match_ctx.value];
|
match_ctx.node = match_ctx.node->children[-match_ctx.value];
|
||||||
struct ctlseqs_trie_node *next_node = match_ctx.node->next;
|
struct ctlseqs_trie_node *next_node = match_ctx.node->next;
|
||||||
matcher->match_stack[++match_stack_top] = (struct ctlseqs_match_ctx) {
|
match_stack[++match_stack_top] = (struct ctlseqs_match_ctx) {
|
||||||
.value = next_node == NULL ? 0 : -next_node->placeholder,
|
.value = next_node == NULL ? 0 : -next_node->placeholder,
|
||||||
.node = old_node,
|
.node = old_node,
|
||||||
.seq = match_ctx.seq,
|
.seq = match_ctx.seq,
|
||||||
|
@ -330,7 +330,7 @@ ctlseqs_match_pattern(struct ctlseqs_matcher const *matcher, struct ctlseqs_matc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (match_stack_top >= 0) {
|
if (match_stack_top >= 0) {
|
||||||
match_ctx = matcher->match_stack[match_stack_top--];
|
match_ctx = match_stack[match_stack_top--];
|
||||||
if (match_ctx.value == 0) {
|
if (match_ctx.value == 0) {
|
||||||
goto match_character;
|
goto match_character;
|
||||||
} else {
|
} else {
|
||||||
|
@ -483,12 +483,7 @@ ctlseqs_matcher_config(struct ctlseqs_matcher *matcher, struct ctlseqs_matcher_o
|
||||||
old_node->value = -ch;
|
old_node->value = -ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size_t stack_size = sizeof(struct ctlseqs_match_ctx) * max_format_size;
|
matcher->match_stack_size = max_format_size;
|
||||||
struct ctlseqs_match_ctx *new_stack = realloc(matcher->match_stack, stack_size);
|
|
||||||
if (CTLSEQS_UNLIKELY(new_stack == NULL)) {
|
|
||||||
return CTLSEQS_NOMEM;
|
|
||||||
}
|
|
||||||
matcher->match_stack = new_stack;
|
|
||||||
return CTLSEQS_OK;
|
return CTLSEQS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,7 +517,6 @@ ctlseqs_matcher_free(struct ctlseqs_matcher *matcher)
|
||||||
for (size_t idx = 0; idx <= matcher->pool_idx; ++idx) {
|
for (size_t idx = 0; idx <= matcher->pool_idx; ++idx) {
|
||||||
free(matcher->node_pools[idx]);
|
free(matcher->node_pools[idx]);
|
||||||
}
|
}
|
||||||
free(matcher->match_stack);
|
|
||||||
free(matcher);
|
free(matcher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user