patch 9.2.0351: repeat_string() can be improved

Commit: 
https://github.com/vim/vim/commit/bfa46a52f6a93cb99ec55d56ad43493d875c6dc2
Author: Yasuhiro Matsumoto <[email protected]>
Date:   Wed Apr 15 04:12:55 2026 +0000

    patch 9.2.0351: repeat_string() can be improved
    
    Problem:  repeat_string() can be improved
    Solution: Replace the for() loop by an exponential growing while loop
              (Yasuhiro Matsumoto)
    
    closes: #19977
    
    Signed-off-by: Yasuhiro Matsumoto <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/evalfunc.c b/src/evalfunc.c
index a0fb99b73..04774128d 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -10584,7 +10584,7 @@ repeat_string(typval_T *str_tv, int n, typval_T *rettv)
     int                slen;
     int                len;
     char_u     *r;
-    int                i;
+    int                done;
 
     p = tv_get_string(str_tv);
     rettv->v_type = VAR_STRING;
@@ -10599,8 +10599,17 @@ repeat_string(typval_T *str_tv, int n, typval_T *rettv)
     if (r == NULL)
        return;
 
-    for (i = 0; i < n; i++)
-       mch_memmove(r + i * slen, p, (size_t)slen);
+    mch_memmove(r, p, (size_t)slen);
+    done = slen;
+    while (done < len)
+    {
+       int copy_len = done;
+
+       if (copy_len > len - done)
+           copy_len = len - done;
+       mch_memmove(r + done, r, (size_t)copy_len);
+       done += copy_len;
+    }
     r[len] = NUL;
 
     rettv->vval.v_string = r;
diff --git a/src/version.c b/src/version.c
index 9aef76d65..3c64afaa9 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    351,
 /**/
     350,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1wD3MO-004IqI-L2%40256bit.org.

Raspunde prin e-mail lui