From f23b9bc6375797d03dee54a31fcaa634f8376975 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 26 Jul 2021 20:59:45 -0700 Subject: Introduced cache to greatly speed up many use cases --- json.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'json.c') diff --git a/json.c b/json.c index 546d99b..23079a7 100644 --- a/json.c +++ b/json.c @@ -18,9 +18,8 @@ static int _json_match(const char *text, match_t *m, int comma, bool verbose) { if (!verbose) { if (m->pat->type != BP_REF && m->pat->type != BP_ERROR) { - for (match_t *child = m->child; child; child = child->nextsibling) { - comma |= _json_match(text, child, comma, verbose); - } + for (int i = 0; m->children && m->children[i]; i++) + comma |= _json_match(text, m->children[i], comma, verbose); return comma; } } @@ -39,9 +38,8 @@ static int _json_match(const char *text, match_t *m, int comma, bool verbose) } printf("\",\"start\":%ld,\"end\":%ld,\"children\":[", m->start - text, m->end - text); - for (match_t *child = m->child; child; child = child->nextsibling) { - comma |= _json_match(text, child, comma, verbose); - } + for (int i = 0; m->children && m->children[i]; i++) + comma |= _json_match(text, m->children[i], comma, verbose); printf("]}"); return 1; } -- cgit v1.2.3