aboutsummaryrefslogtreecommitdiff
path: root/json.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 /json.c
parentd7030709801cde01739850a85f156d181554f520 (diff)
Introduced cache to greatly speed up many use cases
Diffstat (limited to 'json.c')
-rw-r--r--json.c10
1 files changed, 4 insertions, 6 deletions
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;
}