summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorPip Cet <pipcet@gmail.com>2020-09-27 16:59:00 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-09-27 16:59:00 +0200
commit433b6fc53dc9511077ed3a8c1ad130196dedbb55 (patch)
treeef369ccea800d0ab2e00cb189bacefa2e9426efa /lisp/emacs-lisp
parent8d241e8840fdb02dcfce52425626dd8f2125e51a (diff)
downloademacs-433b6fc53dc9511077ed3a8c1ad130196dedbb55.tar.gz
Handle single-argument `apply' consistently (bug#40968)
* src/eval.c (Fapply): Handle (apply nil) without crashing. Document single-argument form. * lisp/emacs-lisp/byte-opt.el (byte-optimize-apply): Don't attempt to optimize single-argument apply. * doc/lispref/functions.texi (Calling Functions): Document single-argument apply. Provide example (bug#40968).
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/byte-opt.el29
1 files changed, 16 insertions, 13 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 8a6c0b9a7fa..65e4e446266 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -1044,19 +1044,22 @@
(defun byte-optimize-apply (form)
;; If the last arg is a literal constant, turn this into a funcall.
;; 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 (= (length form) 2)
+ ;; single-argument `apply' is not worth optimizing (bug#40968)
+ form
+ (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))))
(put 'funcall 'byte-optimizer #'byte-optimize-funcall)
(put 'apply 'byte-optimizer #'byte-optimize-apply)