diff lisp/bytecomp.el @ 4716:dca5bb2adff1

Don't cons with #'mapcar calls where the result is discarded, decide on mapc-internal at compile time if the Common Lisp functionality is not being used. 2009-10-12 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (mapc): New compiler macro, use mapc-internal at compile time if we're not using the Common Lisp functionality. * bytecomp.el (byte-compile-mapcar, byte-compile-maplist): New. If the return value of mapcar is being discarded, compile it to a mapc-internal call instead, and warn, because the programmer probably can't rely on always being compiled by an XEmacs that does this. Similarly for maplist and mapl; and use byte-compile-funarg for map, mapl, mapcan, mapcon.
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 12 Oct 2009 17:19:52 +0100
parents cdabd56ce1b5
children bd51ab22afa8
line wrap: on
line diff
--- a/lisp/bytecomp.el	Mon Oct 12 17:01:15 2009 +0100
+++ b/lisp/bytecomp.el	Mon Oct 12 17:19:52 2009 +0100
@@ -3521,6 +3521,20 @@
 		     (cdr (cdr form))))
        form))))
 
+;; XEmacs change; don't cons up the list if it's going to be immediately
+;; discarded.
+(defun byte-compile-mapcar (form)
+  (and for-effect (setq form (cons 'mapc-internal (cdr form)))
+       (byte-compile-warn
+	"Discarding the result of #'mapcar; maybe you meant #'mapc?"))
+  (byte-compile-funarg form))
+
+(defun byte-compile-maplist (form)
+  (and for-effect (setq form (cons 'mapl (cdr form)))
+       (byte-compile-warn
+	"Discarding the result of #'maplist; maybe you meant #'mapl?"))
+  (byte-compile-funarg form))
+
 ;; (function foo) must compile like 'foo, not like (symbol-function 'foo).
 ;; Otherwise it will be incompatible with the interpreter,
 ;; and (funcall (function foo)) will lose with autoloads.
@@ -3698,9 +3712,14 @@
 (byte-defop-compiler-1 while)
 (byte-defop-compiler-1 funcall)
 (byte-defop-compiler-1 apply byte-compile-funarg)
-(byte-defop-compiler-1 mapcar byte-compile-funarg)
+(byte-defop-compiler-1 mapcar byte-compile-mapcar)
 (byte-defop-compiler-1 mapatoms byte-compile-funarg)
 (byte-defop-compiler-1 mapconcat byte-compile-funarg)
+(byte-defop-compiler-1 map byte-compile-funarg)
+(byte-defop-compiler-1 maplist byte-compile-maplist)
+(byte-defop-compiler-1 mapl byte-compile-funarg)
+(byte-defop-compiler-1 mapcan byte-compile-funarg)
+(byte-defop-compiler-1 mapcon byte-compile-funarg)
 (byte-defop-compiler-1 let)
 (byte-defop-compiler-1 let*)