Function: byte-optimize--pcase
byte-optimize--pcase is a macro defined in byte-opt.el.gz.
Signature
(byte-optimize--pcase EXP &rest CASES)
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/byte-opt.el.gz
(defmacro byte-optimize--pcase (exp &rest cases)
;; When we do
;;
;; (pcase EXP
;; (`(if ,exp ,then ,else) (DO-TEST))
;; (`(plus ,e2 ,e2) (DO-ADD))
;; (`(times ,e2 ,e2) (DO-MULT))
;; ...)
;;
;; we usually don't want to fall back to the default case if
;; the value of EXP is of a form like `(if E1 E2)' or `(plus E1)'
;; or `(times E1 E2 E3)', instead we either want to signal an error
;; that EXP has an unexpected shape, or we want to carry on as if
;; it had the right shape (ignore the extra data and pretend the missing
;; data is nil) because it should simply never happen.
;;
;; The macro below implements the second option by rewriting patterns
;; like `(if ,exp ,then ,else)'
;; to `(if . (or `(,exp ,then ,else) pcase--dontcare))'.
;;
;; The resulting macroexpansion is also significantly cleaner/smaller/faster.
(declare (indent 1) (debug pcase))
`(pcase ,exp
. ,(mapcar (lambda (case)
`(,(pcase (car case)
((and `(,'\` (,_ . (,'\, ,_))) pat) pat)
(`(,'\` (,head . ,tail))
(list '\`
(cons head
(list '\, `(or ,(list '\` tail) pcase--dontcare)))))
(pat pat))
. ,(cdr case)))
cases)))