1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-28 07:45:00 +00:00

Slight replace-in-string optimization

* lisp/subr.el (replace-in-string): Optimize to return the
original string if nothing was replaced (bug#43598).
This commit is contained in:
Lars Ingebrigtsen 2020-09-27 00:17:58 +02:00
parent f43d9d94aa
commit 53cf5936c1

View File

@ -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)