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.
This commit is contained in:
Yuan Fu 2023-09-11 12:47:32 -07:00
parent d11d81dfcc
commit 33ee3e588f
No known key found for this signature in database
GPG key ID: 56E19BC57664A442

View file

@ -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