]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix regression of treesit_cursor_helper_1
authorYuan Fu <casouri@gmail.com>
Mon, 11 Sep 2023 19:47:32 +0000 (12:47 -0700)
committerYuan Fu <casouri@gmail.com>
Mon, 11 Sep 2023 19:50:31 +0000 (12:50 -0700)
* 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

index cb2113b3fafdd3e21dcb000f425db254ba140f6e..8419452d54aa95b3087f9a9c2afe2ec3f28f0258 100644 (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