diff 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
line wrap: on
line diff
--- a/lisp/byte-optimize.el	Thu Sep 16 13:36:03 2010 +0100
+++ b/lisp/byte-optimize.el	Thu Sep 16 13:51:49 2010 +0100
@@ -1119,17 +1119,26 @@
   ;; The funcall optimizer can then transform (funcall 'foo ...) -> (foo ...).
   (let ((fn (nth 1 form))
 	(last (nth (1- (length form)) form))) ; I think this really is fastest
-    (or (if (or (null last)
-		(eq (car-safe last) 'quote))
-	    (if (listp (nth 1 last))
-		(let ((butlast (nreverse (cdr (reverse (cdr (cdr form)))))))
-		  (nconc (list 'funcall fn) butlast
-			 (mapcar #'(lambda (x) (list 'quote x)) (nth 1 last))))
-	      (byte-compile-warn
-	       "last arg to apply can't be a literal atom: %s"
-	       (prin1-to-string last))
-	      nil))
-	form)))
+    (if (and (eq last (third form))
+             (consp last)
+             (eq 'mapcar (car last))
+             (equal fn ''nconc))
+        (progn
+          (byte-compile-warn
+           "(apply 'nconc (mapcar ..)), use #'mapcan instead: %s" last)
+          (cons 'mapcan (cdr last)))
+      (or (if (or (null last)
+                  (eq (car-safe last) 'quote))
+              (if (listp (nth 1 last))
+                  (let ((butlast (nreverse (cdr (reverse (cdr (cdr form)))))))
+                    (nconc (list 'funcall fn) butlast
+                           (mapcar #'(lambda (x) (list 'quote x))
+                                   (nth 1 last))))
+                (byte-compile-warn
+                 "last arg to apply can't be a literal atom: %s"
+                 (prin1-to-string last))
+                nil))
+          form))))
 
 (put 'funcall 'byte-optimizer 'byte-optimize-funcall)
 (put 'apply   'byte-optimizer 'byte-optimize-apply)