Improve performance of seq-union

* lisp/emacs-lisp/seq.el (seq-union): Improve performance by using
nreverse instead of seq-reverse.
This commit is contained in:
Stefan Kangas 2021-09-17 14:01:20 +02:00
parent 0bdd6488fc
commit 3e5298fc96

View 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)