unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Optimize certain memq forms during byte-compilation.
@ 2018-03-23  4:45 Vibhav Pant
  2018-03-23  8:56 ` Robert Pluim
  0 siblings, 1 reply; 3+ messages in thread
From: Vibhav Pant @ 2018-03-23  4:45 UTC (permalink / raw)
  To: emacs-devel; +Cc: Vibhav Pant

* 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 | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index a316364761..e4c5300b0e 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -892,7 +892,20 @@ byte-optimize-identity
 		       (if (= 1 (length (cdr form))) "" "s"))
     form))
 
+(defun byte-optimize-memq (form)
+  (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 (list 'eq (nth 1 form) (list 'quote (nth 0 list))))))
+    (byte-optimize-predicate 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)
@@ -915,7 +928,6 @@ byte-optimize-identity
 (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)
@@ -933,7 +945,6 @@ byte-optimize-identity
 (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,
-- 
2.16.2




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Optimize certain memq forms during byte-compilation.
  2018-03-23  4:45 [PATCH] Optimize certain memq forms during byte-compilation Vibhav Pant
@ 2018-03-23  8:56 ` Robert Pluim
  2018-03-24 18:41   ` Vibhav Pant
  0 siblings, 1 reply; 3+ messages in thread
From: Robert Pluim @ 2018-03-23  8:56 UTC (permalink / raw)
  To: Vibhav Pant; +Cc: emacs-devel

Vibhav Pant <vibhavp@gmail.com> writes:

> * lisp/emacs-lisp/byte-opt.el (byte-optimize-memq): New function.
>   Set the byte optimizer function for memq to byte-optimize-memq.

Is (memq foo '(bar)) actually that common? In any case, some
explanation of the intent of the change would be helpful so we don't
need to read the code every time.

Robert



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Optimize certain memq forms during byte-compilation.
  2018-03-23  8:56 ` Robert Pluim
@ 2018-03-24 18:41   ` Vibhav Pant
  0 siblings, 0 replies; 3+ messages in thread
From: Vibhav Pant @ 2018-03-24 18:41 UTC (permalink / raw)
  To: emacs-devel

On Fri, Mar 23, 2018 at 2:26 PM, Robert Pluim <rpluim@gmail.com> wrote:
> Is (memq foo '(bar)) actually that common?

I've seen it used in the emacs lisp code base, mostly for detecting
the system-type.

> In any case, some explanation of the intent of the change would be helpful
> so we don't need to read the code every time.

I'll add a comment explaining the optimization, yeah.

Thanks,
Vibhav

-- 
Vibhav Pant
vibhavp@gmail.com



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-24 18:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-23  4:45 [PATCH] Optimize certain memq forms during byte-compilation Vibhav Pant
2018-03-23  8:56 ` Robert Pluim
2018-03-24 18:41   ` Vibhav Pant

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).