diff options
author | Stefan Kangas <stefan@marxist.se> | 2021-09-17 14:01:20 +0200 |
---|---|---|
committer | Stefan Kangas <stefan@marxist.se> | 2021-09-17 14:01:20 +0200 |
commit | 3e5298fc96c98d2296432d31ee1d3de86a4c466c (patch) | |
tree | 3aaf685dc8dc840bb8fb9722bf204bdd504c8301 /lisp/emacs-lisp | |
parent | 0bdd6488fc63e9df406fdcf12874a9d12b728208 (diff) | |
download | emacs-3e5298fc96c98d2296432d31ee1d3de86a4c466c.tar.gz emacs-3e5298fc96c98d2296432d31ee1d3de86a4c466c.tar.bz2 emacs-3e5298fc96c98d2296432d31ee1d3de86a4c466c.zip |
Improve performance of seq-union
* lisp/emacs-lisp/seq.el (seq-union): Improve performance by using
nreverse instead of seq-reverse.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/seq.el | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 87aba66daa7..ae5988296d8 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) |