(treesit--indent-rules-optimize): Optimize 'and' and 'or' matcher forms

* lisp/treesit.el (treesit--indent-rules-optimize):
Optimize 'and' and 'or' matcher forms.  When 'and' has a 'query'
matcher inside (as is the case in ruby-ts--indent-rules, many
times over), this yields a significant performance boost.
This commit is contained in:
Dmitry Gutov 2023-01-07 02:44:07 +02:00
parent f2ebe43362
commit ff66a5d324

View file

@ -1546,6 +1546,10 @@ RULES."
(pcase func
(`(query ,qry)
(list 'query (treesit-query-compile lang qry)))
(`(and . ,fns)
(cons 'and (mapcar #'optimize-func fns)))
(`(or . ,fns)
(cons 'or (mapcar #'optimize-func fns)))
(_ func)))
;; Optimize a rule (MATCHER ANCHOR OFFSET).
(optimize-rule (rule)