Mercurial > hg > xemacs-beta
changeset 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 | 0d436a78c514 |
children | 5663ae9a8989 |
files | lisp/ChangeLog lisp/byte-optimize.el lisp/bytecomp-runtime.el lisp/device.el lisp/dumped-lisp.el lisp/etags.el lisp/extents.el lisp/frame.el lisp/packages.el lisp/update-elc.el |
diffstat | 10 files changed, 79 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/ChangeLog Thu Sep 16 13:36:03 2010 +0100 +++ b/lisp/ChangeLog Thu Sep 16 13:51:49 2010 +0100 @@ -1,3 +1,22 @@ +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. + 2010-09-16 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (the): Add a docstring and an implementation for this
--- 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)
--- a/lisp/bytecomp-runtime.el Thu Sep 16 13:36:03 2010 +0100 +++ b/lisp/bytecomp-runtime.el Thu Sep 16 13:51:49 2010 +0100 @@ -53,30 +53,26 @@ "Cause the named functions to be open-coded when called from compiled code. They will only be compiled open-coded when `byte-optimize' is true." (cons 'eval-and-compile - (apply - 'nconc - (mapcar - #'(lambda (x) - `((or (memq (get ',x 'byte-optimizer) - '(nil byte-compile-inline-expand)) - (error - "%s already has a byte-optimizer, can't make it inline" - ',x)) - (put ',x 'byte-optimizer 'byte-compile-inline-expand))) - fns)))) + (mapcan + #'(lambda (x) + `((or (memq (get ',x 'byte-optimizer) + '(nil byte-compile-inline-expand)) + (error + "%s already has a byte-optimizer, can't make it inline" + ',x)) + (put ',x 'byte-optimizer 'byte-compile-inline-expand))) + fns))) (defmacro proclaim-notinline (&rest fns) "Cause the named functions to no longer be open-coded." (cons 'eval-and-compile - (apply - 'nconc - (mapcar - #'(lambda (x) - `((if (eq (get ',x 'byte-optimizer) - 'byte-compile-inline-expand) - (put ',x 'byte-optimizer nil)))) - fns)))) + (mapcan + #'(lambda (x) + `((if (eq (get ',x 'byte-optimizer) + 'byte-compile-inline-expand) + (put ',x 'byte-optimizer nil)))) + fns))) ;; This has a special byte-hunk-handler in bytecomp.el. (defmacro defsubst (name arglist &rest body) @@ -163,7 +159,7 @@ (put 'eval-when-compile 'lisp-indent-hook 0) (defmacro eval-when-compile (&rest body) - "Like `progn', but evaluates the body at compile time. + "Like `progn', but evaluates BODY at compile time, and when interpeted. The result of the body appears to the compiler as a quoted constant." ;; Not necessary because we have it in b-c-initial-macro-environment ;; (list 'quote (eval (cons 'progn body))) @@ -171,7 +167,8 @@ (put 'eval-and-compile 'lisp-indent-hook 0) (defmacro eval-and-compile (&rest body) - "Like `progn', but evaluates the body at compile time and at load time." + "Like `progn', but evaluates the body at compile time and at load time, +and when interpreted." ;; Remember, it's magic. (cons 'progn body))
--- a/lisp/device.el Thu Sep 16 13:36:03 2010 +0100 +++ b/lisp/device.el Thu Sep 16 13:51:49 2010 +0100 @@ -45,7 +45,7 @@ (defun device-list () "Return a list of all devices." - (apply 'nconc (mapcar 'console-device-list (console-list)))) + (mapcan 'console-device-list (console-list))) (defun device-type (&optional device) "Return the type of the specified device (e.g. `x' or `tty').
--- a/lisp/dumped-lisp.el Thu Sep 16 13:36:03 2010 +0100 +++ b/lisp/dumped-lisp.el Thu Sep 16 13:51:49 2010 +0100 @@ -300,7 +300,4 @@ )) (setq preloaded-file-list - (apply #'nconc - (mapcar #'(lambda (x) - (if (listp x) x (list x))) - preloaded-file-list))) + (mapcan #'(lambda (x) (if (listp x) x (list x))) preloaded-file-list))
--- a/lisp/etags.el Thu Sep 16 13:36:03 2010 +0100 +++ b/lisp/etags.el Thu Sep 16 13:51:49 2010 +0100 @@ -439,8 +439,7 @@ (defun buffer-tag-table-files () "Returns a list of all files referenced by all TAGS tables that this buffer uses." - (apply #'append - (mapcar #'tag-table-files (buffer-tag-table-list)))) + (mapcan #'tag-table-files (buffer-tag-table-list))) ;; Building the completion table
--- a/lisp/extents.el Thu Sep 16 13:36:03 2010 +0100 +++ b/lisp/extents.el Thu Sep 16 13:51:49 2010 +0100 @@ -109,7 +109,7 @@ EXTENT, until no more children can be found." (let ((children (extent-children extent))) (if children - (apply 'nconc (mapcar 'extent-descendants children)) + (mapcan 'extent-descendants children) (list extent)))) (defun set-extent-keymap (extent keymap)
--- a/lisp/frame.el Thu Sep 16 13:36:03 2010 +0100 +++ b/lisp/frame.el Thu Sep 16 13:51:49 2010 +0100 @@ -861,7 +861,7 @@ (defun frame-list () "Return a list of all frames on all devices/consoles." ;; Lists are copies, so nconc is safe here. - (apply 'nconc (mapcar 'device-frame-list (device-list)))) + (mapcan #'device-frame-list (device-list))) (defun frame-type (&optional frame) "Return the type of the specified frame (e.g. `x' or `tty').
--- a/lisp/packages.el Thu Sep 16 13:36:03 2010 +0100 +++ b/lisp/packages.el Thu Sep 16 13:51:49 2010 +0100 @@ -467,13 +467,11 @@ PACKAGE-HIERARCHIES is a list of package hierarchies. SUFFIXES is a list of names of hierarchy subdirectories to look for." (let ((directories - (apply - #'nconc - (mapcar #'(lambda (hierarchy) - (mapcar #'(lambda (suffix) - (file-name-as-directory (concat hierarchy suffix))) - suffixes)) - package-hierarchies)))) + (mapcan #'(lambda (hierarchy) + (mapcar #'(lambda (suffix) + (file-name-as-directory (concat hierarchy suffix))) + suffixes)) + package-hierarchies))) (paths-directories-which-exist directories))) (defun packages-find-package-load-path (package-hierarchies)
--- a/lisp/update-elc.el Thu Sep 16 13:36:03 2010 +0100 +++ b/lisp/update-elc.el Thu Sep 16 13:51:49 2010 +0100 @@ -367,21 +367,19 @@ ;; load-ignore-elc-files because byte-optimize gets autoloaded ;; from bytecomp. (let ((recompile-bc-bootstrap - (apply #'nconc - (mapcar - #'(lambda (arg) - (when (member arg update-elc-files-to-compile) - (append '("-f" "batch-byte-compile-one-file") - (list arg)))) - bc-bootstrap))) + (mapcan + #'(lambda (arg) + (when (member arg update-elc-files-to-compile) + (append '("-f" "batch-byte-compile-one-file") + (list arg)))) + bc-bootstrap)) (recompile-bootstrap-other - (apply #'nconc - (mapcar - #'(lambda (arg) - (when (member arg update-elc-files-to-compile) - (append '("-f" "batch-byte-compile-one-file") - (list arg)))) - bootstrap-other)))) + (mapcan + #'(lambda (arg) + (when (member arg update-elc-files-to-compile) + (append '("-f" "batch-byte-compile-one-file") + (list arg)))) + bootstrap-other))) (mapc #'(lambda (arg) (setq update-elc-files-to-compile