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 <mattn.jp@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yasuhiro Matsumoto
2026-04-15 04:12:55 +00:00
committed by Christian Brabandt
parent 351a16c88f
commit bfa46a52f6
2 changed files with 14 additions and 3 deletions
+12 -3
View File
@@ -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;
+2
View File
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
351,
/**/
350,
/**/