Function: byte-optimize-apply

byte-optimize-apply is a byte-compiled function defined in byte-opt.el.gz.

Signature

(byte-optimize-apply FORM)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/byte-opt.el.gz
(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 ...).
  (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))))