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
1 changed files with 15 additions and 11 deletions

View File

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