From 6331d23de3a861de2374be2c03b42e3a2f150792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Wed, 9 Oct 2019 10:22:10 +0200 Subject: Use [^z-a] for matching any character (anychar/anything) in rx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lisp/emacs-lisp/rx.el (rx--translate-symbol): * test/lisp/emacs-lisp/rx-tests.el (rx-any, rx-atoms): Use [^z-a] instead of ".\\|\n" for anychar. The new expression is faster (about 2×) and does not allocate regexp stack space. For example, (0+ anychar) now matches strings of any size (bug#37659). --- test/lisp/emacs-lisp/rx-tests.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/lisp/emacs-lisp') diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el index 903b191c98e..ef2541d83af 100644 --- a/test/lisp/emacs-lisp/rx-tests.el +++ b/test/lisp/emacs-lisp/rx-tests.el @@ -126,9 +126,9 @@ (should (equal (rx (not (any "!a" "0-8" digit nonascii))) "[^!0-8a[:digit:][:nonascii:]]")) (should (equal (rx (any) (not (any))) - "\\`a\\`\\(?:.\\|\n\\)")) + "\\`a\\`[^z-a]")) (should (equal (rx (any "") (not (any ""))) - "\\`a\\`\\(?:.\\|\n\\)"))) + "\\`a\\`[^z-a]"))) (ert-deftest rx-pcase () (should (equal (pcase "a 1 2 3 1 1 b" @@ -185,7 +185,7 @@ (ert-deftest rx-atoms () (should (equal (rx anychar anything) - "\\(?:.\\|\n\\)\\(?:.\\|\n\\)")) + "[^z-a][^z-a]")) (should (equal (rx unmatchable) "\\`a\\`")) (should (equal (rx line-start not-newline nonl any line-end) -- cgit v1.2.1