aboutsummaryrefslogtreecommitdiff
path: root/matchviz.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-07-26 20:59:45 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-07-26 20:59:45 -0700
commitf23b9bc6375797d03dee54a31fcaa634f8376975 (patch)
tree624128655eeb20d68098e8c772d9d3ac77f1ee1e /matchviz.c
parentd7030709801cde01739850a85f156d181554f520 (diff)
Introduced cache to greatly speed up many use cases
Diffstat (limited to 'matchviz.c')
-rw-r--r--matchviz.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/matchviz.c b/matchviz.c
index ebf0ad9..2e917ce 100644
--- a/matchviz.c
+++ b/matchviz.c
@@ -26,8 +26,9 @@ static void _visualize_matches(match_node_t *firstmatch, int depth, const char *
static int height_of_match(match_t *m)
{
int height = 0;
- for (match_t *c = m->child; c; c = c->nextsibling) {
- int childheight = height_of_match(c);
+ for (int i = 0; m->children && m->children[i]; i++) {
+ match_t *child = m->children[i];
+ int childheight = height_of_match(child);
if (childheight > height) height = childheight;
}
return 1 + height;
@@ -83,9 +84,9 @@ static void _visualize_matches(match_node_t *firstmatch, int depth, const char *
// Print nonzero-width first:
for (match_node_t *m = firstmatch; m; m = m->next) {
if (RIGHT_TYPE(m)) {
- for (match_t *c = m->m->child; c; c = c->nextsibling) {
+ for (int i = 0; m->m->children && m->m->children[i]; i++) {
*nextchild = new(match_node_t);
- (*nextchild)->m = c;
+ (*nextchild)->m = m->m->children[i];
nextchild = &((*nextchild)->next);
}
if (m->m->end == m->m->start) continue;