From 33ee3e588fd9744714f1c0ab64de75a61db5eaca Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Mon, 11 Sep 2023 12:47:32 -0700 Subject: [PATCH] Fix regression of treesit_cursor_helper_1 * src/treesit.c (treesit_cursor_helper_1) (treesit_cursor_first_child_for_byte): Use ts_tree_cursor_goto_first_child_for_byte first, and ts_tree_cursor_goto_first_child second. --- src/treesit.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/treesit.c b/src/treesit.c index cb2113b3faf..8419452d54a 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -2160,7 +2160,10 @@ return nil. */) static bool treesit_cursor_first_child_for_byte (TSTreeCursor *cursor, ptrdiff_t pos, bool named) { - if (!ts_tree_cursor_goto_first_child (cursor)) + /* ts_tree_cursor_goto_first_child_for_byte is significantly faster, + so despite it having problems, we try it first. */ + if (ts_tree_cursor_goto_first_child_for_byte (cursor, pos) == -1 + && !ts_tree_cursor_goto_first_child (cursor)) return false; TSNode node = ts_tree_cursor_current_node (cursor); @@ -2890,7 +2893,11 @@ treesit_cursor_helper_1 (TSTreeCursor *cursor, TSNode *target, if (ts_node_eq (cursor_node, *target)) return true; - if (ts_tree_cursor_goto_first_child_for_byte (cursor, start_pos) == -1) + /* ts_tree_cursor_goto_first_child_for_byte is significantly faster, + so despite it having problems (see bug#60127), we try it + first. */ + if (ts_tree_cursor_goto_first_child_for_byte (cursor, start_pos) == -1 + && !ts_tree_cursor_goto_first_child (cursor)) return false; /* Go through each sibling that could contain TARGET. Because of -- 2.39.2