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

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

[elpa] externals/poker 7d978b1 05/12: Very slightly improve performance


From: Stefan Monnier
Subject: [elpa] externals/poker 7d978b1 05/12: Very slightly improve performance
Date: Tue, 1 Dec 2020 16:46:49 -0500 (EST)

branch: externals/poker
commit 7d978b146851c48ff3adb95d59e426e9ff70e124
Author: Mario Lang <mlang@delysid.org>
Commit: Mario Lang <mlang@delysid.org>

    Very slightly improve performance
    
    * packages/poker/poker.el (poker-hand-value): Use `delete-dups' instead of
    `cl-delete-duplicates' and avoid an unnecessary call to `ash'.
---
 poker.el | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/poker.el b/poker.el
index 9de00d3..c908bb6 100644
--- a/poker.el
+++ b/poker.el
@@ -99,25 +99,25 @@ The highest possible value is therefore #x8CBA98 and the 
lowest is #x053210."
                            (lambda (lhs rhs) (or (> (car lhs) (car rhs))
                                                  (and (= (car lhs) (car rhs))
                                                       (> (cdr lhs) (cdr 
rhs)))))))
-        (ranks-length nil))
+        (ranks-length (length rank-counts)))
     (setq ranks (mapcar #'cdr rank-counts)
-         rank-counts (mapcar #'car rank-counts)
-         ranks-length (length ranks))
-    (logior (ash (cond
-                 ((equal rank-counts '(2 1 1 1)) 1)
-                 ((eq ranks-length 5)
-                  (let ((straight (or (when (and (eq (nth 0 ranks) 12)
-                                                  (eq (nth 1 ranks) 3))
-                                         (setq ranks '(3 2 1 0 0)))
-                                       (eq (- (nth 0 ranks) (nth 4 ranks)) 4)))
-                         (flush (eq (length (cl-delete-duplicates
-                                             (mapcar #'poker-card-suit hand))) 
1)))
-                     (cond ((and straight flush) 8) (flush 5) (straight 4) (t 
0))))
-                 ((equal rank-counts '(2 2 1)) 2)
-                 ((equal rank-counts '(3 1 1)) 3)
-                 ((equal rank-counts '(3 2)) 6)
-                 ((equal rank-counts '(4 1)) 7))
-                20)
+         rank-counts (mapcar #'car rank-counts))
+    (logior (cond
+            ((eq ranks-length 4) #x100000)
+            ((eq ranks-length 5)
+             (let ((straight (or (when (and (eq (nth 0 ranks) 12)
+                                            (eq (nth 1 ranks) 3))
+                                   (setq ranks '(3 2 1 0 0)))
+                                 (eq (- (nth 0 ranks) (nth 4 ranks)) 4)))
+                   (flush (not (cdr (delete-dups (mapcar #'poker-card-suit 
hand))))))
+               (cond ((and straight flush) #x800000)
+                     (straight #x400000)
+                     (flush #x500000)
+                     (t 0))))
+            ((equal rank-counts '(2 2 1)) #x200000)
+            ((equal rank-counts '(3 1 1)) #x300000)
+            ((equal rank-counts '(3 2)) #x600000)
+            ((equal rank-counts '(4 1)) #x700000))
            (ash (nth 0 ranks) 16)
            (ash (nth 1 ranks) 12)
            (if (> ranks-length 2) (ash (nth 2 ranks) 8) 0)



reply via email to

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