all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Paul Eggert <eggert@cs.ucla.edu>, emacs-devel <emacs-devel@gnu.org>
Subject: Re: Returning argument string (regexp-quote)
Date: Wed, 25 Sep 2019 15:41:28 +0200	[thread overview]
Message-ID: <4FAEE347-0F67-426F-AA0D-3DB15E3907DC@acm.org> (raw)
In-Reply-To: <83impho4s8.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 829 bytes --]

24 sep. 2019 kl. 21.47 skrev Eli Zaretskii <eliz@gnu.org>:
> 
>> It was responsible for a sizeable portion of local consing in some (non-public) code I was profiling.
> 
> "Sizable portion" meaning what, in quantitative terms?

I no longer have the data, maybe 25-40% in the part of the code that I was looking at. It's not uncommon to use 'regexp-quote' just in case.

> I think it should be in NEWS and in the ELisp manual.  Doc string
> doesn't necessarily have to say that (although it isn't a catastrophe
> if it does), given its current language.

Thanks -- the updated patch includes NEWS and manual amendments, as well as a slightly simplified condition. The manual didn't actually say anything about a new string being returned (in contrast to 'format' before 3db388b0bf), but a note about it won't hurt.


[-- Attachment #2: 0001-Allow-regexp-quote-to-return-its-argument.patch --]
[-- Type: application/octet-stream, Size: 2045 bytes --]

From 95dd4e043ea4635c44b656d0145c6bb67408e47f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Mon, 23 Sep 2019 18:56:30 +0200
Subject: [PATCH] Allow regexp-quote to return its argument

* src/search.c (Fregexp_quote): Only allocate a new string if needed.
---
 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 015871fab0..a4b6533412 100644
--- a/doc/lispref/searching.texi
+++ b/doc/lispref/searching.texi
@@ -1717,6 +1717,9 @@ Regexp Functions
  (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 3f7d4894df..49d733b8ac 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2156,6 +2156,10 @@ valid event type.
 ---
 ** The obsolete package xesam.el (since Emacs 24) has been removed.
 
++++
+** 'regexp-quote' may return its argument string.
+If the argument needs no quoting, it can be returned instead of a copy.
+
 \f
 * Lisp Changes in Emacs 27.1
 
diff --git a/src/search.c b/src/search.c
index 1e57d2ecbe..9d95dcbca5 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;
 }
-- 
2.21.0 (Apple Git-122)


  reply	other threads:[~2019-09-25 13:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-24 11:28 Returning argument string (regexp-quote) Mattias Engdegård
2019-09-24 11:49 ` Andreas Schwab
2019-09-24 16:20 ` Eli Zaretskii
2019-09-24 17:44   ` Mattias Engdegård
2019-09-24 18:24     ` Paul Eggert
2019-09-24 19:47     ` Eli Zaretskii
2019-09-25 13:41       ` Mattias Engdegård [this message]
2019-09-25 15:08         ` Eli Zaretskii
2019-09-25 19:55           ` Compilation failure on macOS 10.15 Catalina Zach Pearson
2019-09-25 20:29             ` mituharu
2019-09-25 21:55               ` Zach Pearson
2019-09-25 22:47                 ` mituharu
2019-09-25 23:07                   ` Zach Pearson
2019-09-25 23:39                     ` mituharu
2019-09-27 23:22                     ` chad
2019-10-02  3:59                       ` Zach Pearson
2019-10-02  4:04                         ` YAMAMOTO Mitsuharu
2019-10-02  4:34                           ` Zach Pearson
2019-10-02  4:42                             ` YAMAMOTO Mitsuharu
2019-10-02  4:43                               ` Zach Pearson
2019-10-02  5:00                                 ` YAMAMOTO Mitsuharu
2019-10-02  5:07                                   ` Zach Pearson
2019-10-02  7:43                                   ` Zach Pearson
2019-10-02 15:15                                     ` Xu Xin
2019-09-26  8:34             ` Robert Pluim
2019-09-26 16:05               ` Zach Pearson
2019-09-26 21:00                 ` mituharu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FAEE347-0F67-426F-AA0D-3DB15E3907DC@acm.org \
    --to=mattiase@acm.org \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.