[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master a773a64: Allow regexp-quote to return its argument
From: |
Mattias Engdegård |
Subject: |
[Emacs-diffs] master a773a64: Allow regexp-quote to return its argument |
Date: |
Wed, 25 Sep 2019 12:11:13 -0400 (EDT) |
branch: master
commit a773a6474897356cd78aeea092d2c1a51ede23f9
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Allow regexp-quote to return its argument
* src/search.c (Fregexp_quote): Only allocate a new string if needed.
* doc/lispref/searching.texi (Regexp Functions):
* etc/NEWS (Incompatible Lisp Changes): Document.
---
doc/lispref/searching.texi | 3 +++
etc/NEWS | 4 ++++
src/search.c | 10 ++++++----
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi
index 1286b63..65f56b4 100644
--- a/doc/lispref/searching.texi
+++ b/doc/lispref/searching.texi
@@ -1562,6 +1562,9 @@ whitespace:
(concat "\\s-" (regexp-quote string) "\\s-"))
@end group
@end example
+
+The returned string may be @var{string} itself if it does not contain
+any special characters.
@end defun
@cindex optimize regexp
diff --git a/etc/NEWS b/etc/NEWS
index 3072d40..96b2cb1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2157,6 +2157,10 @@ valid event type.
be specified in image specs representing the entire bitmap as a single
bool vector.
++++
+** 'regexp-quote' may return its argument string.
+If the argument needs no quoting, it can be returned instead of a copy.
+
* Lisp Changes in Emacs 27.1
diff --git a/src/search.c b/src/search.c
index 1e57d2e..9d95dcb 100644
--- a/src/search.c
+++ b/src/search.c
@@ -3138,10 +3138,12 @@ DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1,
1, 0,
}
Lisp_Object result
- = make_specified_string (temp,
- SCHARS (string) + backslashes_added,
- out - temp,
- STRING_MULTIBYTE (string));
+ = (backslashes_added > 0
+ ? make_specified_string (temp,
+ SCHARS (string) + backslashes_added,
+ out - temp,
+ STRING_MULTIBYTE (string))
+ : string);
SAFE_FREE ();
return result;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master a773a64: Allow regexp-quote to return its argument,
Mattias Engdegård <=