summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2022-07-17 19:05:03 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2022-07-18 12:49:29 +0200
commit5ad8f3e5709a3823371ea6aa039b5e7e50feca1f (patch)
tree96673038a2d4499755be7c31bed4c82c9784b1d8 /lisp/emacs-lisp
parent2d97fe271039358d24a779e5468a313ffcf6059a (diff)
downloademacs-5ad8f3e5709a3823371ea6aa039b5e7e50feca1f.tar.gz
emacs-5ad8f3e5709a3823371ea6aa039b5e7e50feca1f.tar.bz2
emacs-5ad8f3e5709a3823371ea6aa039b5e7e50feca1f.zip
Use `take` where clearly safe to do so (bug#56521)
* lisp/emacs-lisp/seq.el (seq-take): * lisp/auth-source.el (auth-source-secrets-search) (auth-source-plstore-search): * lisp/gnus/message.el (message-insert-formatted-citation-line): * lisp/net/dbus.el (dbus-unregister-object): * lisp/replace.el (occur-context-lines): * test/src/print-tests.el (print-circular): Replace hand-written loop or `butlast` call with `take` for clarity, performance and validation. We have the equivalence (take N LIST) = (butlast LIST (- (length LIST) N)).
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/seq.el12
1 files changed, 7 insertions, 5 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index 36c17f4cd5e..0d9483aecb6 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -587,11 +587,13 @@ Signal an error if SEQUENCE is empty."
(cl-defmethod seq-take ((list list) n)
"Optimized implementation of `seq-take' for lists."
- (let ((result '()))
- (while (and list (> n 0))
- (setq n (1- n))
- (push (pop list) result))
- (nreverse result)))
+ (if (eval-when-compile (fboundp 'take))
+ (take n list)
+ (let ((result '()))
+ (while (and list (> n 0))
+ (setq n (1- n))
+ (push (pop list) result))
+ (nreverse result))))
(cl-defmethod seq-drop-while (pred (list list))
"Optimized implementation of `seq-drop-while' for lists."