From 3b547e4f5dc99dc157b52a059cf234f7a5d15112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Thu, 22 Jan 2026 15:32:13 +0100 Subject: [PATCH] * lisp/emacs-lisp/pcase.el (pcase--macroexpand): Normalise atom etc. Transform (pred P) for P in {atom, nlistp, identity, not} into predicates that pcase already understands in type terms. This doesn't affect the behaviour but generates better code. --- lisp/emacs-lisp/pcase.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index 33d39ecd423..61b8f283bd2 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el @@ -523,7 +523,17 @@ how many time this CODEGEN is called." (cond ((null head) (if (pcase--self-quoting-p pat) `',pat pat)) - ((memq head '(pred guard quote)) pat) + ((memq head '(guard quote)) pat) + ((eq head 'pred) + ;; Ad-hoc expansion of some predicates that are the complement of another. + ;; Not required for correctness but results in better code. + (let* ((expr (cadr pat)) + (compl (assq expr '((atom . consp) + (nlistp . listp) + (identity . null))))) + (cond (compl `(,head (not ,(cdr compl)))) + ((eq expr 'not) `(,head null)) ; normalise + (t pat)))) ((memq head '(or and)) `(,head ,@(mapcar #'pcase--macroexpand (cdr pat)))) ((eq head 'app) `(app ,(nth 1 pat) ,(pcase--macroexpand (nth 2 pat)))) (t