emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] feature/gnus-select 2f67ad3 208/218: Optimize certain memq


From: Andrew G Cohen
Subject: [Emacs-diffs] feature/gnus-select 2f67ad3 208/218: Optimize certain memq forms during byte-compilation.
Date: Fri, 14 Dec 2018 03:35:45 -0500 (EST)

branch: feature/gnus-select
commit 2f67ad35d7d6dac283093b6daa6d8cad94c9df9b
Author: Vibhav Pant <address@hidden>
Commit: Andrew G Cohen <address@hidden>

    Optimize certain memq forms during byte-compilation.
    
    * lisp/emacs-lisp/byte-opt.el (byte-optimize-memq): New function.
      Set the byte optimizer function for memq to byte-optimize-memq.
---
 lisp/emacs-lisp/byte-opt.el | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index a5e0e21..54421e0 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -764,7 +764,23 @@
                       (if (= 1 (length (cdr form))) "" "s"))
     form))
 
+(defun byte-optimize-memq (form)
+  ;; (memq foo '(bar)) => (and (eq foo 'bar) '(bar))
+  (if (/= (length (cdr form)) 2)
+      (byte-compile-warn "memq called with %d arg%s, but requires 2"
+                        (length (cdr form))
+                        (if (= 1 (length (cdr form))) "" "s"))
+    (let ((list (nth 2 form)))
+      (when (and (eq (car-safe list) 'quote)
+                 (listp (setq list (cadr list)))
+                 (= (length list) 1))
+        (setq form `(and ,(byte-optimize-predicate
+                           `(eq ,(nth 1 form) ',(nth 0 list)))
+                         ',list))))
+    (byte-optimize-and form)))
+
 (put 'identity 'byte-optimizer 'byte-optimize-identity)
+(put 'memq 'byte-optimizer 'byte-optimize-memq)
 
 (put '+   'byte-optimizer 'byte-optimize-plus)
 (put '*   'byte-optimizer 'byte-optimize-multiply)
@@ -787,7 +803,6 @@
 (put '1-  'byte-optimizer 'byte-optimize-predicate)
 (put 'not 'byte-optimizer 'byte-optimize-predicate)
 (put 'null  'byte-optimizer 'byte-optimize-predicate)
-(put 'memq  'byte-optimizer 'byte-optimize-predicate)
 (put 'consp 'byte-optimizer 'byte-optimize-predicate)
 (put 'listp 'byte-optimizer 'byte-optimize-predicate)
 (put 'symbolp 'byte-optimizer 'byte-optimize-predicate)
@@ -805,7 +820,6 @@
 (put 'car-safe 'byte-optimizer 'byte-optimize-predicate)
 (put 'cdr-safe 'byte-optimizer 'byte-optimize-predicate)
 
-
 ;; I'm not convinced that this is necessary.  Doesn't the optimizer loop
 ;; take care of this? - Jamie
 ;; I think this may some times be necessary to reduce ie (quote 5) to 5,



reply via email to

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