vim-patch:9.2.0147: blob: concatenation can be improved (#38276)

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: vim/vim#19645

67deae3b77

Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
This commit is contained in:
zeertzjq
2026-03-13 07:28:26 +08:00
committed by GitHub
parent 52dd62aa6e
commit 878c9739e1

View File

@@ -39,8 +39,11 @@ static int tv_op_blob(typval_T *tv1, const typval_T *tv2, const char *op)
blob_T *const b2 = tv2->vval.v_blob;
const int len = tv_blob_len(b2);
for (int i = 0; i < len; i++) {
ga_append(&b1->bv_ga, tv_blob_get(b2, i));
if (len > 0) {
ga_grow(&b1->bv_ga, len);
memmove((uint8_t *)b1->bv_ga.ga_data + b1->bv_ga.ga_len,
(uint8_t *)b2->bv_ga.ga_data, (size_t)len);
b1->bv_ga.ga_len += len;
}
return OK;