]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve performance of seq-union
authorStefan Kangas <stefan@marxist.se>
Fri, 17 Sep 2021 12:01:20 +0000 (14:01 +0200)
committerStefan Kangas <stefan@marxist.se>
Fri, 17 Sep 2021 12:01:20 +0000 (14:01 +0200)
* lisp/emacs-lisp/seq.el (seq-union): Improve performance by using
nreverse instead of seq-reverse.

lisp/emacs-lisp/seq.el

index 87aba66daa774a94d807c7811cff0f32c9f6ca2a..ae5988296d8f2174648b2cc21cf82ac9b9f93840 100644 (file)
@@ -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)