1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-07 06:50:23 -08:00

(pcase-mutually-exclusive): Use auto-generated table

The `pcase-mutually-exclusive-predicates` table was not very
efficient since it grew like O(N²) with the number of
predicates.  Replace it with an O(N) table that's auto-generated
from the `built-in-class` objects.

* lisp/emacs-lisp/pcase.el (pcase-mutually-exclusive-predicates):
Delete variable.
(pcase--subtype-bitsets): New function and constant.
(pcase--mutually-exclusive-p): Use them.
* lisp/emacs-lisp/cl-preloaded.el (built-in-class): Don't inline.
This commit is contained in:
Stefan Monnier 2024-03-28 00:06:00 -04:00
parent 1552f8345d
commit f1fe13ea05
3 changed files with 92 additions and 55 deletions

View file

@ -160,4 +160,18 @@
(should-error (pcase-setq a)
:type '(wrong-number-of-arguments)))
(ert-deftest pcase-tests-mutually-exclusive ()
(dolist (x '((functionp consp nil)
(functionp stringp t)
(compiled-function-p consp t)
(keywordp symbolp nil)
(keywordp symbol-with-pos-p nil)
(keywordp stringp t)))
(if (nth 2 x)
(should (pcase--mutually-exclusive-p (nth 0 x) (nth 1 x)))
(should-not (pcase--mutually-exclusive-p (nth 0 x) (nth 1 x))))
(if (nth 2 x)
(should (pcase--mutually-exclusive-p (nth 1 x) (nth 0 x)))
(should-not (pcase--mutually-exclusive-p (nth 1 x) (nth 0 x))))))
;;; pcase-tests.el ends here.