Commit 35744400 authored by IRIE Shinsuke's avatar IRIE Shinsuke Committed by Glenn Morris
Browse files

* lisp/subr.el (last): Make it faster.

Fixes: debbugs:7174
parent 290fe464
2010-10-13 IRIE Shinsuke <irieshinsuke@yahoo.co.jp> (tiny change)
* subr.el (last): Make it faster. (Bug#7174)
2010-10-13 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> (tiny change)
 
* Makefile.in (compile-clean): Use `` instead of $(). (Bug#7178)
......
......@@ -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."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment