From f2ebe43362cab1b8d88674dad60b1ed3c822bb54 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sat, 7 Jan 2023 02:02:25 +0200 Subject: [PATCH] (treesit-simple-indent-presets): Short-circuit 'and' and 'or' * lisp/treesit.el (treesit-simple-indent-presets): Short-circuit the 'and' and 'or' matchers. To avoid calling all fns after one returned nil or truthy value, respectively. --- lisp/treesit.el | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index 987942c507a..a85eb699ee1 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -1179,16 +1179,15 @@ See `treesit-simple-indent-presets'.") ;; TODO: Document. (cons 'and (lambda (&rest fns) (lambda (node parent bol &rest _) - (cl-reduce (lambda (a b) (and a b)) - (mapcar (lambda (fn) - (funcall fn node parent bol)) - fns))))) + (not + (seq-find + (lambda (fn) (not (funcall fn node parent bol))) + fns))))) (cons 'or (lambda (&rest fns) (lambda (node parent bol &rest _) - (cl-reduce (lambda (a b) (or a b)) - (mapcar (lambda (fn) - (funcall fn node parent bol)) - fns))))) + (seq-find + (lambda (fn) (funcall fn node parent bol)) + fns)))) (cons 'not (lambda (fn) (lambda (node parent bol &rest _) (not (funcall fn node parent bol))))) -- 2.39.5