emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 f2ebe43362 1/2: (treesit-simple-indent-presets): Short-circuit


From: Dmitry Gutov
Subject: emacs-29 f2ebe43362 1/2: (treesit-simple-indent-presets): Short-circuit 'and' and 'or'
Date: Fri, 6 Jan 2023 19:45:42 -0500 (EST)

branch: emacs-29
commit f2ebe43362cab1b8d88674dad60b1ed3c822bb54
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    (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 987942c507..a85eb699ee 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)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]