Skip to content

Commit 7a66142

Browse files
stsewdda-x
authored andcommitted
Performance: Use nvim_buf_set_lines for neovim
`setline()` gets called for every item on the array, this results on the neovim buffer callbacks to be called `n` times, using `nvim_buf_set_lines()` makes this change in just one call
1 parent 87c745d commit 7a66142

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

autoload/rustfmt.vim

+8-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,14 @@ function! s:RunRustfmt(command, tmpname, from_writepre)
157157
endif
158158

159159
call s:DeleteLines(len(l:content), line('$'))
160-
call setline(1, l:content)
160+
if has('nvim') && exists('*nvim_buf_set_lines')
161+
" setline() gets called for every item on the array,
162+
" this results on the neovim buffer callbacks being called n times,
163+
" using nvim_buf_set_lines() makes the change in one call.
164+
call nvim_buf_set_lines(0, 0, -1, v:true, l:content)
165+
else
166+
call setline(1, l:content)
167+
endif
161168

162169
" only clear location list if it was previously filled to prevent
163170
" clobbering other additions

0 commit comments

Comments
 (0)