]> git.eshelyaron.com Git - emacs.git/commit
pcase.el (\`): Try and handle large patterns better
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 3 Jun 2024 17:26:10 +0000 (13:26 -0400)
committerEshel Yaron <me@eshelyaron.com>
Mon, 3 Jun 2024 19:33:27 +0000 (21:33 +0200)
commit58c8859a9d217dcb1e10ae65e03aaf736aa41224
treef269f992a5c04cb90559df8b2860a81d32e3ca64
parent5a261610b46b7da71bb1596bfb38ca7c27d3de79
pcase.el (\`): Try and handle large patterns better

Large backquote patterns tend to lead to very large and deeply
nested expansions, but they also tend to contain a lot of
"constant" subpatterns that can be compiled to quote patterns.
This patch does just that.  See discussion at
https://lists.gnu.org/archive/html/emacs-devel/2024-05/msg01140.html

* lisp/emacs-lisp/pcase.el (pcase--split-pred):
Improve the handling of pred-vs-quote so it also works with
quoted objects like cons cells, vectors, and strings.
Simplify the `pcase--mutually-exclusive-p` branch accordingly.
(pcase--expand-\`): New function, extracted from the \` pcase macro.
Make it recurse internally, and optimize backquote patterns to `quote`
patterns where possible.
(\`): Use it.

* test/lisp/emacs-lisp/pcase-tests.el (pcase-tests-vectors): Add tests
that were broken by a more naïve version of the optimization.
(pcase-tests-quote-optimization): New test.

(cherry picked from commit 16fc5b6c0c72464a75d9a84b754375662b3acec6)
lisp/emacs-lisp/pcase.el
test/lisp/emacs-lisp/pcase-tests.el