changeset 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 a357478dd457
children fcc7e89d5e68
files lisp/ChangeLog lisp/bytecomp.el lisp/cl-macs.el
diffstat 3 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Oct 12 17:01:15 2009 +0100
+++ b/lisp/ChangeLog	Mon Oct 12 17:19:52 2009 +0100
@@ -1,3 +1,15 @@
+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. 
+
 2009-10-12  Aidan Kehoe  <kehoea@parhasard.net>
 
 	* cl-macs.el (delete-duplicates): 
--- 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*)
 
--- a/lisp/cl-macs.el	Mon Oct 12 17:01:15 2009 +0100
+++ b/lisp/cl-macs.el	Mon Oct 12 17:19:52 2009 +0100
@@ -3259,6 +3259,13 @@
           (t
            form))))
 
+;; XEmacs change, the GNU mapc doesn't accept the Common Lisp args, so this
+;; change isn't helpful.
+(define-compiler-macro mapc (&whole form cl-func cl-seq &rest cl-rest)
+  (if cl-rest
+      form
+    (cons 'mapc-internal (cdr form))))
+
 (mapc
  #'(lambda (y)
      (put (car y) 'side-effect-free t)