[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master a140513: Optimize certain memq forms during byte-co
From: |
Vibhav Pant |
Subject: |
[Emacs-diffs] master a140513: Optimize certain memq forms during byte-compilation. |
Date: |
Sat, 24 Mar 2018 15:30:58 -0400 (EDT) |
branch: master
commit a140513acb4ce27bd2b3472ee7a6ecb92676a8e9
Author: Vibhav Pant <address@hidden>
Commit: Vibhav Pant <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,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master a140513: Optimize certain memq forms during byte-compilation.,
Vibhav Pant <=