diff options
| author | Paul Eggert | 2018-12-17 09:54:14 -0800 |
|---|---|---|
| committer | Paul Eggert | 2018-12-17 10:26:15 -0800 |
| commit | 8664ba18c7c56bc463f69dd5b131b4071612d567 (patch) | |
| tree | 22c2c3807b1a25503169fca8879528b399423722 | |
| parent | 4d77c4ac3b9c40c62b1505bcaa1e0377d63a4956 (diff) | |
| download | emacs-8664ba18c7c56bc463f69dd5b131b4071612d567.tar.gz emacs-8664ba18c7c56bc463f69dd5b131b4071612d567.zip | |
Improve flatten-tree performance
* lisp/subr.el (flatten-tree): Improve performance by calling
‘cons’ once rather than twice when a cons cell is popped.
| -rw-r--r-- | lisp/subr.el | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 7a7c175db4a..3dec6cf66c3 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -5460,14 +5460,14 @@ elements are removed. | |||
| 5460 | TREE can be anything that can be made into a list. For each | 5460 | TREE can be anything that can be made into a list. For each |
| 5461 | element in TREE, if it is a cons cell return its car | 5461 | element in TREE, if it is a cons cell return its car |
| 5462 | recursively. Otherwise return the element." | 5462 | recursively. Otherwise return the element." |
| 5463 | (let (elems) | 5463 | (let (elems) |
| 5464 | (setq tree (list tree)) | 5464 | (while (consp tree) |
| 5465 | (while (let ((elem (pop tree))) | 5465 | (let ((elem (pop tree))) |
| 5466 | (cond ((consp elem) | 5466 | (while (consp elem) |
| 5467 | (setq tree (cons (car elem) (cons (cdr elem) tree)))) | 5467 | (push (cdr elem) tree) |
| 5468 | (elem | 5468 | (setq elem (car elem))) |
| 5469 | (push elem elems))) | 5469 | (if elem (push elem elems)))) |
| 5470 | tree)) | 5470 | (if tree (push tree elems)) |
| 5471 | (nreverse elems))) | 5471 | (nreverse elems))) |
| 5472 | 5472 | ||
| 5473 | ;; Technically, `flatten-list' is a misnomer, but we provide it here | 5473 | ;; Technically, `flatten-list' is a misnomer, but we provide it here |