[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 8664ba1 1/4: Improve flatten-tree performance
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] master 8664ba1 1/4: Improve flatten-tree performance |
Date: |
Mon, 17 Dec 2018 13:26:21 -0500 (EST) |
branch: master
commit 8664ba18c7c56bc463f69dd5b131b4071612d567
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>
Improve flatten-tree performance
* lisp/subr.el (flatten-tree): Improve performance by calling
‘cons’ once rather than twice when a cons cell is popped.
---
lisp/subr.el | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/lisp/subr.el b/lisp/subr.el
index 7a7c175..3dec6cf 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -5460,14 +5460,14 @@ elements are removed.
TREE can be anything that can be made into a list. For each
element in TREE, if it is a cons cell return its car
recursively. Otherwise return the element."
- (let (elems)
- (setq tree (list tree))
- (while (let ((elem (pop tree)))
- (cond ((consp elem)
- (setq tree (cons (car elem) (cons (cdr elem) tree))))
- (elem
- (push elem elems)))
- tree))
+ (let (elems)
+ (while (consp tree)
+ (let ((elem (pop tree)))
+ (while (consp elem)
+ (push (cdr elem) tree)
+ (setq elem (car elem)))
+ (if elem (push elem elems))))
+ (if tree (push tree elems))
(nreverse elems)))
;; Technically, `flatten-list' is a misnomer, but we provide it here