From ff66a5d324b6cc88db27f48f351f2cb5baa08fa2 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sat, 7 Jan 2023 02:44:07 +0200 Subject: [PATCH] (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. --- lisp/treesit.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lisp/treesit.el b/lisp/treesit.el index a85eb699ee1..374c17c0894 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -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) -- 2.39.2