From c28f4a47e9a9395781530de5839e426e4aa2b3e0 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Tue, 5 Feb 2019 14:23:20 +0300 Subject: [PATCH] json.c: add a comment Add a comment explaining the logic behind intermediate lookups in json_tree_lookup_path() function. --- src/lib/json/json.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib/json/json.c b/src/lib/json/json.c index 010a61d621..1b1a3ec2c0 100644 --- a/src/lib/json/json.c +++ b/src/lib/json/json.c @@ -565,6 +565,17 @@ json_tree_lookup_path(struct json_tree *tree, struct json_token *root, json_lexer_create(&lexer, path, path_len, index_base); while ((rc = json_lexer_next_token(&lexer, &token)) == 0 && token.type != JSON_TOKEN_END && ret != NULL) { + /* + * We could skip intermediate lookups by computing + * a rolling hash of all tokens produced by the + * lexer. But then we would still have to traverse + * the path back to ensure it is equal to the + * found to the found one. For that we would have + * to keep the stack of lexer tokens somewhere. + * Given the complications of the alternative, + * intermediate lookups don't seem to be so big of + * a problem. + */ ret = json_tree_lookup(tree, ret, &token); } if (rc != 0 || token.type != JSON_TOKEN_END) -- GitLab