Function: byte-optimize-associative-math

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

Signature

(byte-optimize-associative-math FORM)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/byte-opt.el.gz
;; If the function is being called with constant integer args,
;; evaluate as much as possible at compile-time.  This optimizer
;; assumes that the function is associative, like min or max.
(defun byte-optimize-associative-math (form)
  (let ((args nil)
	(constants nil)
	(rest (cdr form)))
    (while rest
      (if (integerp (car rest))
	  (setq constants (cons (car rest) constants))
	  (setq args (cons (car rest) args)))
      (setq rest (cdr rest)))
    (if (cdr constants)
        (let ((const (apply (car form) (nreverse constants))))
	  (if args
	      (append (list (car form) const)
                      (nreverse args))
	    const))
      form)))