comparison 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
comparison
equal deleted inserted replaced
4715:a357478dd457 4716:dca5bb2adff1
3519 (cons (car form) 3519 (cons (car form)
3520 (cons (cons 'function (cdr fn)) 3520 (cons (cons 'function (cdr fn))
3521 (cdr (cdr form)))) 3521 (cdr (cdr form))))
3522 form)))) 3522 form))))
3523 3523
3524 ;; XEmacs change; don't cons up the list if it's going to be immediately
3525 ;; discarded.
3526 (defun byte-compile-mapcar (form)
3527 (and for-effect (setq form (cons 'mapc-internal (cdr form)))
3528 (byte-compile-warn
3529 "Discarding the result of #'mapcar; maybe you meant #'mapc?"))
3530 (byte-compile-funarg form))
3531
3532 (defun byte-compile-maplist (form)
3533 (and for-effect (setq form (cons 'mapl (cdr form)))
3534 (byte-compile-warn
3535 "Discarding the result of #'maplist; maybe you meant #'mapl?"))
3536 (byte-compile-funarg form))
3537
3524 ;; (function foo) must compile like 'foo, not like (symbol-function 'foo). 3538 ;; (function foo) must compile like 'foo, not like (symbol-function 'foo).
3525 ;; Otherwise it will be incompatible with the interpreter, 3539 ;; Otherwise it will be incompatible with the interpreter,
3526 ;; and (funcall (function foo)) will lose with autoloads. 3540 ;; and (funcall (function foo)) will lose with autoloads.
3527 3541
3528 (defun byte-compile-function-form (form) 3542 (defun byte-compile-function-form (form)
3696 (byte-defop-compiler-1 and) 3710 (byte-defop-compiler-1 and)
3697 (byte-defop-compiler-1 or) 3711 (byte-defop-compiler-1 or)
3698 (byte-defop-compiler-1 while) 3712 (byte-defop-compiler-1 while)
3699 (byte-defop-compiler-1 funcall) 3713 (byte-defop-compiler-1 funcall)
3700 (byte-defop-compiler-1 apply byte-compile-funarg) 3714 (byte-defop-compiler-1 apply byte-compile-funarg)
3701 (byte-defop-compiler-1 mapcar byte-compile-funarg) 3715 (byte-defop-compiler-1 mapcar byte-compile-mapcar)
3702 (byte-defop-compiler-1 mapatoms byte-compile-funarg) 3716 (byte-defop-compiler-1 mapatoms byte-compile-funarg)
3703 (byte-defop-compiler-1 mapconcat byte-compile-funarg) 3717 (byte-defop-compiler-1 mapconcat byte-compile-funarg)
3718 (byte-defop-compiler-1 map byte-compile-funarg)
3719 (byte-defop-compiler-1 maplist byte-compile-maplist)
3720 (byte-defop-compiler-1 mapl byte-compile-funarg)
3721 (byte-defop-compiler-1 mapcan byte-compile-funarg)
3722 (byte-defop-compiler-1 mapcon byte-compile-funarg)
3704 (byte-defop-compiler-1 let) 3723 (byte-defop-compiler-1 let)
3705 (byte-defop-compiler-1 let*) 3724 (byte-defop-compiler-1 let*)
3706 3725
3707 (defun byte-compile-progn (form) 3726 (defun byte-compile-progn (form)
3708 (byte-compile-body-do-effect (cdr form))) 3727 (byte-compile-body-do-effect (cdr form)))