Simplify storage of position on nodes
This commit is contained in:
parent
da7eb1496b
commit
8a9626bfc5
4 changed files with 12 additions and 22 deletions
|
|
@ -63,7 +63,7 @@ void ts_document_set_input_string(TSDocument *document, const char *text) {
|
|||
|
||||
TSNode ts_document_root_node(const TSDocument *document) {
|
||||
if (document->tree)
|
||||
return ts_node_make(document->tree, document->tree->padding);
|
||||
return ts_node_make(document->tree, ts_length_zero());
|
||||
else
|
||||
return ts_node_null();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ static inline const TSTree *get_tree(TSNode this) {
|
|||
}
|
||||
|
||||
TSLength ts_node_pos(TSNode this) {
|
||||
return this.position;
|
||||
return ts_length_add(this.position, get_tree(this)->padding);
|
||||
}
|
||||
|
||||
TSLength ts_node_size(TSNode this) {
|
||||
|
|
@ -41,7 +41,7 @@ typedef struct {
|
|||
static inline NodeWithIndex ts_node_parent_with_index(TSNode this) {
|
||||
const TSTree *tree = get_tree(this);
|
||||
size_t index = 0;
|
||||
TSLength position = ts_length_sub(this.position, tree->padding);
|
||||
TSLength position = this.position;
|
||||
|
||||
do {
|
||||
TSTree *parent = tree->parent;
|
||||
|
|
@ -64,9 +64,7 @@ static inline NodeWithIndex ts_node_parent_with_index(TSNode this) {
|
|||
tree = parent;
|
||||
} while (!ts_tree_is_visible(tree));
|
||||
|
||||
return (NodeWithIndex){
|
||||
ts_node_make(tree, ts_length_add(position, tree->padding)), index
|
||||
};
|
||||
return (NodeWithIndex){ ts_node_make(tree, position), index };
|
||||
}
|
||||
|
||||
TSNode ts_node_parent(TSNode this) {
|
||||
|
|
|
|||
|
|
@ -101,9 +101,6 @@ TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count,
|
|||
TSTree *child = children[i];
|
||||
child->parent = result;
|
||||
|
||||
if (i > 0)
|
||||
offset = ts_length_add(offset, child->padding);
|
||||
|
||||
if (ts_tree_is_visible(child)) {
|
||||
visible_children[vis_i].tree = child;
|
||||
visible_children[vis_i].offset = offset;
|
||||
|
|
@ -119,7 +116,7 @@ TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count,
|
|||
}
|
||||
}
|
||||
|
||||
offset = ts_length_add(offset, child->size);
|
||||
offset = ts_length_add(offset, ts_tree_total_size(child));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue