1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-19 12:20:17 -08:00

(Ftreesit_query_capture): Cache list of predicates for given pattern index

* src/treesit.c (Ftreesit_query_capture):
Cache list of predicates for given pattern index (bug#60953).
This commit is contained in:
Dmitry Gutov 2023-02-01 03:45:55 +02:00
parent 47ab9ba55d
commit f711f4e99f

View file

@ -2720,8 +2720,10 @@ the query. */)
every for loop and nconc it to RESULT every time. That is indeed every for loop and nconc it to RESULT every time. That is indeed
the initial implementation in which Yoav found nconc being the the initial implementation in which Yoav found nconc being the
bottleneck (98.4% of the running time spent on nconc). */ bottleneck (98.4% of the running time spent on nconc). */
uint32_t patterns_count = ts_query_pattern_count (treesit_query);
Lisp_Object result = Qnil; Lisp_Object result = Qnil;
Lisp_Object prev_result = result; Lisp_Object prev_result = result;
Lisp_Object predicates_table = make_vector (patterns_count, Qt);
while (ts_query_cursor_next_match (cursor, &match)) while (ts_query_cursor_next_match (cursor, &match))
{ {
/* Record the checkpoint that we may roll back to. */ /* Record the checkpoint that we may roll back to. */
@ -2750,9 +2752,12 @@ the query. */)
result = Fcons (cap, result); result = Fcons (cap, result);
} }
/* Get predicates. */ /* Get predicates. */
Lisp_Object predicates Lisp_Object predicates = AREF (predicates_table, match.pattern_index);
= treesit_predicates_for_pattern (treesit_query, if (EQ (predicates, Qt))
match.pattern_index); {
predicates = treesit_predicates_for_pattern (treesit_query, 0);
ASET (predicates_table, match.pattern_index, predicates);
}
/* captures_lisp = Fnreverse (captures_lisp); */ /* captures_lisp = Fnreverse (captures_lisp); */
struct capture_range captures_range = { result, prev_result }; struct capture_range captures_range = { result, prev_result };