From 85335157dd4a8bf6a0c92525360ec35362750c30 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Wed, 28 Jun 2023 14:36:39 +0200 Subject: [PATCH] Speed up duplicate-dwim and duplicate-line by another factor 10 * lisp/misc.el (duplicate--insert-copies): New. (duplicate-line, duplicate-dwim): Call it. --- lisp/misc.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lisp/misc.el b/lisp/misc.el index de82b97fa6f..ab083728a69 100644 --- a/lisp/misc.el +++ b/lisp/misc.el @@ -63,6 +63,10 @@ Also see the `duplicate-line' command." (+ n (point))))))) (insert string))) +(defun duplicate--insert-copies (n string) + "Insert N copies of STRING at point." + (insert (mapconcat #'identity (make-list n string)))) + ;;;###autoload (defun duplicate-line (&optional n) "Duplicate the current line N times. @@ -78,8 +82,7 @@ Also see the `copy-from-above-command' command." (forward-line 1) (unless (bolp) (insert "\n")) - (dotimes (_ n) - (insert line))))) + (duplicate--insert-copies n line)))) (declare-function rectangle--duplicate-right "rect" (n)) @@ -111,8 +114,7 @@ Interactively, N is the prefix numeric argument, and defaults to 1." (text (buffer-substring beg end))) (save-excursion (goto-char end) - (dotimes (_ n) - (insert text)))) + (duplicate--insert-copies n text))) (setq deactivate-mark nil)) ;; Duplicate line. -- 2.39.2