Function: byte-optimize-plus

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

Signature

(byte-optimize-plus FORM)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/byte-opt.el.gz
(defun byte-optimize-plus (form)
  (let* ((not-0 (remq 0 (byte-opt--arith-reduce #'+ 0 (cdr form))))
         (args (if (and (= (length not-0) 1)
                        (> (length form) 2))
                   ;; We removed numbers and only one arg remains: add a 0
                   ;; so that it isn't turned into (* X 1) later on.
                   (append not-0 '(0))
                 not-0)))
    (cond
     ;; (+) -> 0
     ((null args) 0)
     ;; (+ n) -> n, where n is a number
     ((and (null (cdr args)) (numberp (car args))) (car args))
     ;; (+ x 1) --> (1+ x) and (+ x -1) --> (1- x).
     ((and (null (cddr args)) (or (memq 1 args) (memq -1 args)))
      (let* ((arg1 (car args)) (arg2 (cadr args))
             (integer-is-first (memq arg1 '(1 -1)))
             (integer (if integer-is-first arg1 arg2))
             (other (if integer-is-first arg2 arg1)))
        (list (if (eq integer 1) '1+ '1-) other)))
     ;; (+ x y z) -> (+ (+ x y) z)
     ((= (length args) 3)
      `(+ ,(byte-optimize-plus `(+ ,(car args) ,(cadr args))) ,@(cddr args)))
     ;; not further optimized
     ((equal args (cdr form)) form)
     (t (cons '+ args)))))