performance improvements: cache errors and warnings explicitly

There are many calls to s:Errors() and s:Warnings(), and previously the
location list was filtered once for each of these calls. This made vim
unusable when handling large location lists (with hundreds of entries).
Now we cache the errors and warnings explicitly when we cache the
location list.

Rework some of the minor methods so that they call s:Errors() or
s:Warnings() (which use the cached data) instead of calling
s:FilterLocList() directly (which is expensive).
This commit is contained in:
Martin Grenfell 2012-02-18 15:54:22 +00:00
parent e44494558f
commit b4a7d47294

View File

@ -160,8 +160,10 @@ function! s:LocList()
endfunction endfunction
"clear the loc list for the buffer "clear the loc list for the buffer
function! s:ClearLocList() function! s:ClearCache()
let b:syntastic_loclist = [] let b:syntastic_loclist = []
unlet! b:syntastic_errors
unlet! b:syntastic_warnings
endfunction endfunction
"detect and cache all syntax errors in this buffer "detect and cache all syntax errors in this buffer
@ -169,7 +171,7 @@ endfunction
"depends on a function called SyntaxCheckers_{&ft}_GetLocList() existing "depends on a function called SyntaxCheckers_{&ft}_GetLocList() existing
"elsewhere "elsewhere
function! s:CacheErrors() function! s:CacheErrors()
call s:ClearLocList() call s:ClearCache()
if filereadable(expand("%")) if filereadable(expand("%"))
@ -195,7 +197,7 @@ function! s:ToggleMode()
let g:syntastic_mode_map['mode'] = "active" let g:syntastic_mode_map['mode'] = "active"
endif endif
call s:ClearLocList() call s:ClearCache()
call s:UpdateErrors(1) call s:UpdateErrors(1)
echo "Syntastic: " . g:syntastic_mode_map['mode'] . " mode enabled" echo "Syntastic: " . g:syntastic_mode_map['mode'] . " mode enabled"
@ -217,30 +219,22 @@ function! s:ModeMapAllowsAutoChecking()
endif endif
endfunction endfunction
"return true if there are cached errors/warnings for this buf
function! s:BufHasErrorsOrWarnings()
return !empty(s:LocList())
endfunction
"return true if there are cached errors for this buf
function! s:BufHasErrors()
return len(s:ErrorsForType('E')) > 0
endfunction
function! s:BufHasErrorsOrWarningsToDisplay() function! s:BufHasErrorsOrWarningsToDisplay()
return s:BufHasErrors() || (!g:syntastic_quiet_warnings && s:BufHasErrorsOrWarnings()) return len(s:Errors()) || (!g:syntastic_quiet_warnings && !empty(s:LocList()))
endfunction
function! s:ErrorsForType(type)
return s:FilterLocList({'type': a:type})
endfunction endfunction
function! s:Errors() function! s:Errors()
return s:ErrorsForType("E") if !exists("b:syntastic_errors")
let b:syntastic_errors = s:FilterLocList({'type': "E"})
endif
return b:syntastic_errors
endfunction endfunction
function! s:Warnings() function! s:Warnings()
return s:ErrorsForType("W") if !exists("b:syntastic_warnings")
let b:syntastic_warnings = s:FilterLocList({'type': "W"})
endif
return b:syntastic_warnings
endfunction endfunction
"Filter a loc list (defaults to s:LocList()) by a:filters "Filter a loc list (defaults to s:LocList()) by a:filters