emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/dash 71668fe 003/316: Speed up -table-flat


From: ELPA Syncer
Subject: [elpa] externals/dash 71668fe 003/316: Speed up -table-flat
Date: Mon, 15 Feb 2021 15:57:13 -0500 (EST)

branch: externals/dash
commit 71668fe6ac901092c7afd13455812a73d1e04c57
Author: Magnar Sveen <magnars@gmail.com>
Commit: Magnar Sveen <magnars@gmail.com>

    Speed up -table-flat
    
    A proposed change from Stefan Monnier. He writes:
    
      The patch speeds up -table-flat by 25% (worst-case) and a factor
      4x (base case) in my tests, where `fn' was the addition function.
      I'll leave it as an exercise to adapt this idea to -table ;-)
---
 dash.el | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/dash.el b/dash.el
index aceff8b9..7cb844c 100644
--- a/dash.el
+++ b/dash.el
@@ -1102,14 +1102,18 @@ of the result.  This is equivalent to calling:
 but the implementation here is much more efficient.
 
 See also: `-flatten-n', `-table'"
-  (let ((restore-lists (copy-sequence lists))
-        (last-list (last lists))
-        re)
-    (while (car last-list)
-      (push (apply fn (-map 'car lists)) re)
-      (pop (car lists))
-      (dash--table-carry lists restore-lists))
-    (nreverse re)))
+  (when lists                           ;Just in case.
+    (let* ((list1 (pop lists))
+           (restore-lists (copy-sequence lists))
+           (last-list (last lists))
+           re)
+      (while (car last-list)
+        (let ((tail (-map #'car lists)))
+          (dolist (head list1)
+            (push (apply fn head tail) re)))
+        (pop (car lists))
+        (dash--table-carry lists restore-lists))
+      (nreverse re))))
 
 (defun -partial (fn &rest args)
   "Take a function FN and fewer than the normal arguments to FN,



reply via email to

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