Function: byte-optimize-cond
byte-optimize-cond is a byte-compiled function defined in
byte-opt.el.gz.
Signature
(byte-optimize-cond FORM)
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/byte-opt.el.gz
(defun byte-optimize-cond (form)
;; if any clauses have a literal nil as their test, throw them away.
;; if any clause has a literal non-nil constant as its test, throw
;; away all following clauses.
(let (rest)
;; This must be first, to reduce (cond (t ...) (nil)) to (progn t ...)
(while (setq rest (assq nil (cdr form)))
(setq form (remq rest form)))
(setq form (remq nil form))
(setq rest form)
(while (setq rest (cdr rest))
(cond ((byte-compile-trueconstp (car-safe (car rest)))
;; This branch will always be taken: kill the subsequent ones.
(cond ((eq rest (cdr form)) ;First branch of `cond'.
(setq form `(progn ,@(car rest))))
((cdr rest)
(setq form (copy-sequence form))
(setcdr (memq (car rest) form) nil)))
(setq rest nil))
((and (consp (car rest))
(byte-compile-nilconstp (caar rest)))
;; This branch will never be taken: kill its body.
(setcdr (car rest) nil)))))
;;
;; Turn (cond (( <x> )) ... ) into (or <x> (cond ... ))
(if (eq 'cond (car-safe form))
(let ((clauses (cdr form)))
(if (and (consp (car clauses))
(null (cdr (car clauses))))
(list 'or (car (car clauses))
(byte-optimize-cond
(cons (car form) (cdr (cdr form)))))
(and clauses form)))
form))