emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master a812ed2: Speed up cl-list-length


From: Paul Eggert
Subject: [Emacs-diffs] master a812ed2: Speed up cl-list-length
Date: Mon, 18 Feb 2019 17:52:42 -0500 (EST)

branch: master
commit a812ed215ce0a7a53f51dd5aa51de720917d2ff0
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    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.
---
 lisp/emacs-lisp/cl-extra.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el
index 99b55ad..a2400a0 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)."
 ;;;###autoload
 (defun cl-list-length (x)
   "Return the length of list X.  Return nil if list is circular."
-  (let ((n 0) (fast x) (slow x))
-    (while (and (cdr fast) (not (and (eq fast slow) (> n 0))))
-      (setq n (+ n 2) fast (cdr (cdr fast)) slow (cdr slow)))
-    (if fast (if (cdr fast) nil (1+ n)) n)))
+  (cl-check-type x list)
+  (condition-case nil
+      (length x)
+    (circular-list)))
 
 ;;;###autoload
 (defun cl-tailp (sublist list)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]