aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2019-02-18 14:51:26 -0800
committerPaul Eggert2019-02-18 14:52:37 -0800
commita812ed215ce0a7a53f51dd5aa51de720917d2ff0 (patch)
treeac452d74428b3522b76c6c5c1906242e78da472d
parent5d46862440af7957ea617e42d6c1c6ee4c46ba3e (diff)
downloademacs-a812ed215ce0a7a53f51dd5aa51de720917d2ff0.tar.gz
emacs-a812ed215ce0a7a53f51dd5aa51de720917d2ff0.zip
Speed up cl-list-length
* lisp/emacs-lisp/cl-extra.el (cl-list-length): Use ‘length’ to do the real work; this is simpler and uses a better algorithm.
-rw-r--r--lisp/emacs-lisp/cl-extra.el8
1 files changed, 4 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el
index 99b55ad6b72..a2400a0ba37 100644
--- a/lisp/emacs-lisp/cl-extra.el
+++ b/lisp/emacs-lisp/cl-extra.el
@@ -594,10 +594,10 @@ too large if positive or too small if negative)."
594;;;###autoload 594;;;###autoload
595(defun cl-list-length (x) 595(defun cl-list-length (x)
596 "Return the length of list X. Return nil if list is circular." 596 "Return the length of list X. Return nil if list is circular."
597 (let ((n 0) (fast x) (slow x)) 597 (cl-check-type x list)
598 (while (and (cdr fast) (not (and (eq fast slow) (> n 0)))) 598 (condition-case nil
599 (setq n (+ n 2) fast (cdr (cdr fast)) slow (cdr slow))) 599 (length x)
600 (if fast (if (cdr fast) nil (1+ n)) n))) 600 (circular-list)))
601 601
602;;;###autoload 602;;;###autoload
603(defun cl-tailp (sublist list) 603(defun cl-tailp (sublist list)