[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 0b9cdba 2/2: Speed up -flatten-n a bit
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash 0b9cdba 2/2: Speed up -flatten-n a bit |
Date: |
Sun, 28 Feb 2021 07:57:09 -0500 (EST) |
branch: externals/dash
commit 0b9cdbaa31c7ae2406722fd9c534aad8f38fa1d5
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>
Speed up -flatten-n a bit
* dash.el (-flatten-n): Don't maintain a list of intermediate
results. Eta-reduce.
* dev/examples.el (-flatten-n): Check for destructive side effects.
Re: #373.
---
dash.el | 4 +++-
dev/examples.el | 5 ++++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/dash.el b/dash.el
index 9187c66..86f37c3 100644
--- a/dash.el
+++ b/dash.el
@@ -727,7 +727,9 @@ See also: `-flatten-n'"
See also: `-flatten'"
(declare (pure t) (side-effect-free t))
- (-last-item (--iterate (--mapcat (-list it) it) list (1+ num))))
+ (dotimes (_ num)
+ (setq list (apply #'append (mapcar #'-list list))))
+ list)
(defun -concat (&rest lists)
"Return a new list with the concatenation of the elements in the supplied
LISTS."
diff --git a/dev/examples.el b/dev/examples.el
index a0b115f..6997d89 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -344,7 +344,10 @@ new list."
(-flatten-n 0 '(3 4)) => '(3 4)
(-flatten-n 0 '((1 2) (3 4))) => '((1 2) (3 4))
(-flatten-n 0 '(((1 2) (3 4)))) => '(((1 2) (3 4)))
- (-flatten-n 1 '(((1 . 2)) ((3 . 4)))) => '((1 . 2) (3 . 4)))
+ (-flatten-n 1 '(((1 . 2)) ((3 . 4)))) => '((1 . 2) (3 . 4))
+ (let ((l (list 1 (list 2) 3))) (-flatten-n 0 l) l) => '(1 (2) 3)
+ (let ((l (list 1 (list 2) 3))) (-flatten-n 1 l) l) => '(1 (2) 3)
+ (let ((l (list 1 (list 2) 3))) (-flatten-n 2 l) l) => '(1 (2) 3))
(defexamples -replace
(-replace 1 "1" '(1 2 3 4 3 2 1)) => '("1" 2 3 4 3 2 "1")