Reduce allocations in string .= and .. operations by using vim_realloc() to grow the existing buffer in place, avoiding an alloc/copy/free cycle on every concatenation.
| Operation | Before | After | Change |
|---|---|---|---|
.= (append) |
0.4877s | 0.3957s | -19% |
.. (concat) |
0.1511s | 0.1490s | (noise) |
Note
The improvement is most visible with .= because the left-hand string grows repeatedly (e.g. let s .= 'x' in a loop). Without this patch, each iteration requires alloc/copy-all/free, making it O(n²) overall. vim_realloc() can often extend the buffer in place, avoiding the full copy. The .. benchmark concatenates two small fixed-size literals, so the copy cost is negligible regardless of the allocation strategy.
https://github.com/vim/vim/pull/19642
(1 file)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()