From fe3be2aa5381e30021c5e9583e7a5c881d9f4359 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 9 Sep 2015 12:43:35 -0700 Subject: [PATCH] Optimize Node parent() method --- src/runtime/node.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/runtime/node.c b/src/runtime/node.c index e3f64787..4629f6d2 100644 --- a/src/runtime/node.c +++ b/src/runtime/node.c @@ -183,16 +183,10 @@ TSNode ts_node_parent(TSNode this) { TSLength position = ts_node__offset(this); do { - TSTree *parent = tree->context.parent; - if (!parent) + position = ts_length_sub(position, tree->context.offset); + tree = tree->context.parent; + if (!tree) return ts_node__null(); - - for (size_t i = 0; i < tree->context.index; i++) { - TSTree *child = parent->children[i]; - position = ts_length_sub(position, ts_tree_total_size(child)); - } - - tree = parent; } while (!ts_tree_is_visible(tree)); return ts_node_make(tree, position);