emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 53cf593 1/3: Slight replace-in-string optimization


From: Lars Ingebrigtsen
Subject: master 53cf593 1/3: Slight replace-in-string optimization
Date: Sat, 26 Sep 2020 18:25:02 -0400 (EDT)

branch: master
commit 53cf5936c19a6c7352483323666c3915de6f7746
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Slight replace-in-string optimization
    
    * lisp/subr.el (replace-in-string): Optimize to return the
    original string if nothing was replaced (bug#43598).
---
 lisp/subr.el | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index dd79702..357eae0 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4442,10 +4442,13 @@ Unless optional argument INPLACE is non-nil, return a 
new string."
         (push (substring instring start pos) result))
       (push tostring result)
       (setq start (+ pos (length fromstring))))
-    ;; Get any remaining bit.
-    (unless (= start (length instring))
-      (push (substring instring start) result))
-    (apply #'concat (nreverse result))))
+    (if (null result)
+        ;; No replacements were done, so just return the original string.
+        instring
+      ;; Get any remaining bit.
+      (unless (= start (length instring))
+        (push (substring instring start) result))
+      (apply #'concat (nreverse result)))))
 
 (defun replace-regexp-in-string (regexp rep string &optional
                                        fixedcase literal subexp start)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]