emacs-diffs
[Top][All Lists]
Advanced

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

master 3e5298f: Improve performance of seq-union


From: Stefan Kangas
Subject: master 3e5298f: Improve performance of seq-union
Date: Fri, 17 Sep 2021 08:01:59 -0400 (EDT)

branch: master
commit 3e5298fc96c98d2296432d31ee1d3de86a4c466c
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    Improve performance of seq-union
    
    * lisp/emacs-lisp/seq.el (seq-union): Improve performance by using
    nreverse instead of seq-reverse.
---
 lisp/emacs-lisp/seq.el | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index 87aba66..ae59882 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -471,13 +471,13 @@ negative integer or 0, nil is returned."
 (cl-defgeneric seq-union (sequence1 sequence2 &optional testfn)
   "Return a list of all elements that appear in either SEQUENCE1 or SEQUENCE2.
 Equality is defined by TESTFN if non-nil or by `equal' if nil."
-  (let ((accum (lambda (acc elt)
-                 (if (seq-contains-p acc elt testfn)
-                     acc
-                   (cons elt acc)))))
-    (seq-reverse
-     (seq-reduce accum sequence2
-                 (seq-reduce accum sequence1 '())))))
+  (let* ((accum (lambda (acc elt)
+                  (if (seq-contains-p acc elt testfn)
+                      acc
+                    (cons elt acc))))
+         (result (seq-reduce accum sequence2
+                          (seq-reduce accum sequence1 '()))))
+    (nreverse result)))
 
 ;;;###autoload
 (cl-defgeneric seq-intersection (sequence1 sequence2 &optional testfn)



reply via email to

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