# HG changeset patch # User Aidan Kehoe # Date 1255364392 -3600 # Node ID dca5bb2adff1b80bbab692ed963d06a22e9be546 # Parent a357478dd457c5e9ec91eb4a5ac270628ed4468c 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 * 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. diff -r a357478dd457 -r dca5bb2adff1 lisp/ChangeLog --- 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 + + * 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 * cl-macs.el (delete-duplicates): diff -r a357478dd457 -r dca5bb2adff1 lisp/bytecomp.el --- 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*) diff -r a357478dd457 -r dca5bb2adff1 lisp/cl-macs.el --- 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)