aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Gutov2023-02-01 03:45:55 +0200
committerDmitry Gutov2023-02-01 03:45:55 +0200
commitf711f4e99f7f2b213e70d14c808261b93ed10c36 (patch)
tree1627f398f12896a9f4d8b85ae929f6be7557996c /src
parent47ab9ba55d77746a666bfa0819ccb465184949dc (diff)
downloademacs-f711f4e99f7f2b213e70d14c808261b93ed10c36.tar.gz
emacs-f711f4e99f7f2b213e70d14c808261b93ed10c36.zip
(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).
Diffstat (limited to 'src')
-rw-r--r--src/treesit.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/treesit.c b/src/treesit.c
index b210ec0923a..a5815903b4d 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -2720,8 +2720,10 @@ the query. */)
2720 every for loop and nconc it to RESULT every time. That is indeed 2720 every for loop and nconc it to RESULT every time. That is indeed
2721 the initial implementation in which Yoav found nconc being the 2721 the initial implementation in which Yoav found nconc being the
2722 bottleneck (98.4% of the running time spent on nconc). */ 2722 bottleneck (98.4% of the running time spent on nconc). */
2723 uint32_t patterns_count = ts_query_pattern_count (treesit_query);
2723 Lisp_Object result = Qnil; 2724 Lisp_Object result = Qnil;
2724 Lisp_Object prev_result = result; 2725 Lisp_Object prev_result = result;
2726 Lisp_Object predicates_table = make_vector (patterns_count, Qt);
2725 while (ts_query_cursor_next_match (cursor, &match)) 2727 while (ts_query_cursor_next_match (cursor, &match))
2726 { 2728 {
2727 /* Record the checkpoint that we may roll back to. */ 2729 /* Record the checkpoint that we may roll back to. */
@@ -2750,9 +2752,12 @@ the query. */)
2750 result = Fcons (cap, result); 2752 result = Fcons (cap, result);
2751 } 2753 }
2752 /* Get predicates. */ 2754 /* Get predicates. */
2753 Lisp_Object predicates 2755 Lisp_Object predicates = AREF (predicates_table, match.pattern_index);
2754 = treesit_predicates_for_pattern (treesit_query, 2756 if (EQ (predicates, Qt))
2755 match.pattern_index); 2757 {
2758 predicates = treesit_predicates_for_pattern (treesit_query, 0);
2759 ASET (predicates_table, match.pattern_index, predicates);
2760 }
2756 2761
2757 /* captures_lisp = Fnreverse (captures_lisp); */ 2762 /* captures_lisp = Fnreverse (captures_lisp); */
2758 struct capture_range captures_range = { result, prev_result }; 2763 struct capture_range captures_range = { result, prev_result };