Make updating linter results slightly faster when the list is empty

This commit is contained in:
w0rp 2018-03-02 12:10:27 +00:00
parent 1d0690f6d7
commit 2096562899

View File

@ -145,35 +145,39 @@ function! s:GatherOutput(job_id, line) abort
endfunction
function! s:HandleLoclist(linter_name, buffer, loclist) abort
let l:buffer_info = get(g:ale_buffer_info, a:buffer, {})
let l:info = get(g:ale_buffer_info, a:buffer, {})
if empty(l:buffer_info)
if empty(l:info)
return
endif
" Remove this linter from the list of active linters.
" This may have already been done when the job exits.
call filter(l:buffer_info.active_linter_list, 'v:val isnot# a:linter_name')
call filter(l:info.active_linter_list, 'v:val isnot# a:linter_name')
" Make some adjustments to the loclists to fix common problems, and also
" to set default values for loclist items.
let l:linter_loclist = ale#engine#FixLocList(a:buffer, a:linter_name, a:loclist)
" Remove previous items for this linter.
call filter(g:ale_buffer_info[a:buffer].loclist, 'v:val.linter_name isnot# a:linter_name')
" Add the new items.
call extend(g:ale_buffer_info[a:buffer].loclist, l:linter_loclist)
call filter(l:info.loclist, 'v:val.linter_name isnot# a:linter_name')
" Sort the loclist again.
" We need a sorted list so we can run a binary search against it
" for efficient lookup of the messages in the cursor handler.
call sort(g:ale_buffer_info[a:buffer].loclist, 'ale#util#LocItemCompare')
" We don't need to add items or sort the list when this list is empty.
if !empty(l:linter_loclist)
" Add the new items.
call extend(l:info.loclist, l:linter_loclist)
" Sort the loclist again.
" We need a sorted list so we can run a binary search against it
" for efficient lookup of the messages in the cursor handler.
call sort(l:info.loclist, 'ale#util#LocItemCompare')
endif
if ale#ShouldDoNothing(a:buffer)
return
endif
call ale#engine#SetResults(a:buffer, g:ale_buffer_info[a:buffer].loclist)
call ale#engine#SetResults(a:buffer, l:info.loclist)
endfunction
function! s:HandleExit(job_id, exit_code) abort