diff options
author | IRIE Shinsuke <irieshinsuke@yahoo.co.jp> | 2010-10-12 20:30:36 -0700 |
---|---|---|
committer | Glenn Morris <rgm@gnu.org> | 2010-10-12 20:30:36 -0700 |
commit | 3574440031b0fc21c98c188a2fa15705381cbe24 (patch) | |
tree | 2d4ffaf16145647a0251e12170b14a36334c5df2 /lisp/subr.el | |
parent | 290fe46441c67f2c533fe549024ad14bf490690b (diff) | |
download | emacs-3574440031b0fc21c98c188a2fa15705381cbe24.tar.gz |
* lisp/subr.el (last): Make it faster.
Fixes: debbugs:7174
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 484340895be..0ed4ae62795 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -289,14 +289,11 @@ If LIST is nil, return nil. If N is non-nil, return the Nth-to-last link of LIST. If N is bigger than the length of LIST, return LIST." (if n - (let ((m 0) (p list)) - (while (consp p) - (setq m (1+ m) p (cdr p))) - (if (<= n 0) p - (if (< n m) (nthcdr (- m n) list) list))) - (while (consp (cdr list)) - (setq list (cdr list))) - list)) + (and (> n 0) + (let ((m (length list))) + (if (< n m) (nthcdr (- m n) list) list))) + (and list + (nthcdr (1- (length list)) list)))) (defun butlast (list &optional n) "Return a copy of LIST with the last N elements removed." |