patch 9.2.0147: blob: concatenation can be improved

Problem:  blob: concatenation can be improved
Solution: Use ga_grow() to allocate space once and mch_memmove() to copy
          the blob data as a single block and fall back to the previous
          byte by byte append (Yasuhiro Matsumoto).

closes: #19645

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-03-12 19:35:42 +00:00
committed by Christian Brabandt
parent 97a75d835b
commit 67deae3b77
2 changed files with 11 additions and 2 deletions
+9 -2
View File
@@ -2553,8 +2553,15 @@ tv_op_blob(typval_T *tv1, typval_T *tv2, char_u *op)
blob_T *b2 = tv2->vval.v_blob;
int len = blob_len(b2);
for (int i = 0; i < len; i++)
ga_append(&b1->bv_ga, blob_get(b2, i));
if (len > 0 && ga_grow(&b1->bv_ga, len) == OK)
{
mch_memmove((char_u *)b1->bv_ga.ga_data + b1->bv_ga.ga_len,
(char_u *)b2->bv_ga.ga_data, (size_t)len);
b1->bv_ga.ga_len += len;
}
else
for (int i = 0; i < len; i++)
(void)ga_append(&b1->bv_ga, blob_get(b2, i));
return OK;
}
+2
View File
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
147,
/**/
146,
/**/