From 2096562899aa0994a2c6d2c30320810001d98591 Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 2 Mar 2018 12:10:27 +0000 Subject: [PATCH] Make updating linter results slightly faster when the list is empty --- autoload/ale/engine.vim | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index a21eecd..9ef3ba3 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -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