comparison lisp/byte-optimize.el @ 5264:0d43872986b6

Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form. lisp/ChangeLog addition: 2010-09-16 Aidan Kehoe <kehoea@parhasard.net> * byte-optimize.el (byte-optimize-apply): Transform (apply 'nconc (mapcar ...)) to (mapcan ...); warn about use of the first idiom. * update-elc.el (do-autoload-commands): * packages.el (packages-find-package-library-path): * frame.el (frame-list): * extents.el (extent-descendants): * etags.el (buffer-tag-table-files): * dumped-lisp.el (preloaded-file-list): * device.el (device-list): * bytecomp-runtime.el (proclaim-inline, proclaim-notinline) Use #'mapcan, not (apply #'nconc (mapcar ...) in all these files. * bytecomp-runtime.el (eval-when-compile, eval-and-compile): In passing, mention that these macros also evaluate the body when interpreted.
author Aidan Kehoe <kehoea@parhasard.net>
date Thu, 16 Sep 2010 13:51:49 +0100
parents 2d0937dc83cf
children 99de5fd48e87 308d34e9f07d
comparison
equal deleted inserted replaced
5263:0d436a78c514 5264:0d43872986b6
1117 (defun byte-optimize-apply (form) 1117 (defun byte-optimize-apply (form)
1118 ;; If the last arg is a literal constant, turn this into a funcall. 1118 ;; If the last arg is a literal constant, turn this into a funcall.
1119 ;; The funcall optimizer can then transform (funcall 'foo ...) -> (foo ...). 1119 ;; The funcall optimizer can then transform (funcall 'foo ...) -> (foo ...).
1120 (let ((fn (nth 1 form)) 1120 (let ((fn (nth 1 form))
1121 (last (nth (1- (length form)) form))) ; I think this really is fastest 1121 (last (nth (1- (length form)) form))) ; I think this really is fastest
1122 (or (if (or (null last) 1122 (if (and (eq last (third form))
1123 (eq (car-safe last) 'quote)) 1123 (consp last)
1124 (if (listp (nth 1 last)) 1124 (eq 'mapcar (car last))
1125 (let ((butlast (nreverse (cdr (reverse (cdr (cdr form))))))) 1125 (equal fn ''nconc))
1126 (nconc (list 'funcall fn) butlast 1126 (progn
1127 (mapcar #'(lambda (x) (list 'quote x)) (nth 1 last)))) 1127 (byte-compile-warn
1128 (byte-compile-warn 1128 "(apply 'nconc (mapcar ..)), use #'mapcan instead: %s" last)
1129 "last arg to apply can't be a literal atom: %s" 1129 (cons 'mapcan (cdr last)))
1130 (prin1-to-string last)) 1130 (or (if (or (null last)
1131 nil)) 1131 (eq (car-safe last) 'quote))
1132 form))) 1132 (if (listp (nth 1 last))
1133 (let ((butlast (nreverse (cdr (reverse (cdr (cdr form)))))))
1134 (nconc (list 'funcall fn) butlast
1135 (mapcar #'(lambda (x) (list 'quote x))
1136 (nth 1 last))))
1137 (byte-compile-warn
1138 "last arg to apply can't be a literal atom: %s"
1139 (prin1-to-string last))
1140 nil))
1141 form))))
1133 1142
1134 (put 'funcall 'byte-optimizer 'byte-optimize-funcall) 1143 (put 'funcall 'byte-optimizer 'byte-optimize-funcall)
1135 (put 'apply 'byte-optimizer 'byte-optimize-apply) 1144 (put 'apply 'byte-optimizer 'byte-optimize-apply)
1136 1145
1137 1146