branch: externals/substitute commit 73a1904ea4521f9bf149f658950b6ed7252622c4 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Do not check for fn in 'while' loop We only want to perform the test once, not per iteration. --- substitute.el | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/substitute.el b/substitute.el index 51014e1d64..b3023e21d4 100644 --- a/substitute.el +++ b/substitute.el @@ -163,14 +163,12 @@ Pass to it the TARGET and SCOPE arguments." (defun substitute--operate (target sub &optional scope) "Substitute TARGET with SUB in SCOPE. This is the subroutine of `substitute-target' and related." - (let (count) + (let ((count) + (search-fn (if (eq scope 'above) 're-search-backward 're-search-forward))) (save-excursion (save-restriction (substitute--setup-scope target scope) - (while (funcall (if (eq scope 'above) - 're-search-backward - 're-search-forward) - target nil t) + (while (funcall search-fn target nil t) (push (match-string-no-properties 0) count) (replace-match sub nil t)))) (run-hook-with-args 'substitute-post-replace-hook