[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 6331d23 3/3: Use [^z-a] for matching any character
From: |
Mattias Engdegård |
Subject: |
[Emacs-diffs] master 6331d23 3/3: Use [^z-a] for matching any character (anychar/anything) in rx |
Date: |
Fri, 18 Oct 2019 08:48:22 -0400 (EDT) |
branch: master
commit 6331d23de3a861de2374be2c03b42e3a2f150792
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Use [^z-a] for matching any character (anychar/anything) in rx
* 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).
---
lisp/emacs-lisp/rx.el | 2 +-
test/lisp/emacs-lisp/rx-tests.el | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el
index cf02df2..87b3133 100644
--- a/lisp/emacs-lisp/rx.el
+++ b/lisp/emacs-lisp/rx.el
@@ -136,7 +136,7 @@ Each entry is:
;; Use `list' instead of a quoted list to wrap the strings here,
;; since the return value may be mutated.
((or 'nonl 'not-newline 'any) (cons (list ".") t))
- ((or 'anychar 'anything) (rx--translate-form '(or nonl "\n")))
+ ((or 'anychar 'anything) (cons (list "[^z-a]") t))
('unmatchable (rx--empty))
((or 'bol 'line-start) (cons (list "^") 'lseq))
((or 'eol 'line-end) (cons (list "$") 'rseq))
diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el
index 903b191..ef2541d 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)