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

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

[elpa] externals/dash 9065e1b 344/439: [-let] Final cdr shift optimizati


From: Phillip Lord
Subject: [elpa] externals/dash 9065e1b 344/439: [-let] Final cdr shift optimization
Date: Tue, 04 Aug 2015 20:30:01 +0000

branch: externals/dash
commit 9065e1bdaa990b38ab22cb32b9b8132e58c71612
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>

    [-let] Final cdr shift optimization
---
 dash.el         |   16 ++++++++++++----
 dev/examples.el |    8 +++++++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/dash.el b/dash.el
index 7e7db7e..a66d3cb 100644
--- a/dash.el
+++ b/dash.el
@@ -1198,11 +1198,19 @@ SOURCE is a proper or improper list."
      ;; because each bind-body has a side-effect of chopping the head
      ;; of the list, we must create a binding even for _ places
      ((symbolp (car match-form))
-      (cons (list (car match-form) `(prog1 (car ,s) (!cdr ,s)))
-            (dash--match-cons-1 (cdr match-form) s)))
+      (cond
+       ((cdr match-form)
+        (cons (list (car match-form) `(prog1 (car ,s) (!cdr ,s)))
+              (dash--match-cons-1 (cdr match-form) s)))
+       (t
+        (list (list (car match-form) `(car ,s))))))
      (t
-      (-concat (dash--match (car match-form) `(prog1 (car ,s) (!cdr ,s)))
-               (dash--match-cons-1 (cdr match-form) s)))))
+      (cond
+       ((cdr match-form)
+        (-concat (dash--match (car match-form) `(prog1 (car ,s) (!cdr ,s)))
+                 (dash--match-cons-1 (cdr match-form) s)))
+       (t
+        (dash--match (car match-form) `(car ,s)))))))
    ((eq match-form nil)
     nil)
    (t
diff --git a/dev/examples.el b/dev/examples.el
index aa171f4..ae4c643 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -740,7 +740,13 @@ new list."
             (list a b c d)
             (error "previous call should fail.")))
       (error t)) => t
-    (-let [(a . (b . c)) (cons 1 (cons 2 3))] (list a b c)) => '(1 2 3))
+    (-let [(a . (b . c)) (cons 1 (cons 2 3))] (list a b c)) => '(1 2 3)
+    ;; final cdr optimization
+    (-let [(((a))) (list (list (list 1 2) 3) 4)] a) => 1
+    (-let [(((a b) c) d) (list (list (list 1 2) 3) 4)] (list a b c d)) => '(1 
2 3 4)
+    (-let [(((a b) . c) . d) (list (list (list 1 2) 3) 4)] (list a b c d)) => 
'(1 2 (3) (4))
+    (-let [(((a b) c)) (list (list (list 1 2) 3) 4)] (list a b c)) => '(1 2 3)
+    (-let [(((a b) . c)) (list (list (list 1 2) 3) 4)] (list a b c)) => '(1 2 
(3)))
 
   (defexamples -let*
     (-let* (((a . b) (cons 1 2))



reply via email to

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