c syntax_checker: major performance improvements

This commit is contained in:
kongo2002 2010-10-19 03:14:49 +08:00 committed by Chris Hoffman
parent 9b66271e39
commit 1473b7dcdb

View File

@ -98,10 +98,10 @@ function! SyntaxCheckers_c_GetLocList()
\ g:syntastic_c_no_include_search != 1 \ g:syntastic_c_no_include_search != 1
if exists('g:syntastic_c_auto_refresh_includes') && if exists('g:syntastic_c_auto_refresh_includes') &&
\ g:syntastic_c_auto_refresh_includes != 0 \ g:syntastic_c_auto_refresh_includes != 0
let makeprg .= s:SearchHeaders(s:handlers) let makeprg .= s:SearchHeaders()
else else
if !exists('b:syntastic_c_includes') if !exists('b:syntastic_c_includes')
let b:syntastic_c_includes = s:SearchHeaders(s:handlers) let b:syntastic_c_includes = s:SearchHeaders()
endif endif
let makeprg .= b:syntastic_c_includes let makeprg .= b:syntastic_c_includes
endif endif
@ -115,20 +115,24 @@ endfunction
" search the first 100 lines for include statements that are " search the first 100 lines for include statements that are
" given in the s:handlers dictionary " given in the s:handlers dictionary
function! s:SearchHeaders(handlers) function! s:SearchHeaders()
let includes = '' let includes = ''
let l:handlers = copy(a:handlers)
let files = [] let files = []
let found = []
let lines = filter(getline(1, 100), 'v:val =~# "#\s*include"')
" search current buffer " search current buffer
for i in range(100) for line in lines
for handler in l:handlers let file = matchstr(line, '"\zs\S\+\ze"')
let line = getline(i) if file != ''
if line =~# '^#include.*' . handler["regex"] call add(files, file)
continue
endif
for handler in s:handlers
if line =~# handler["regex"]
let includes .= call(handler["func"], handler["args"]) let includes .= call(handler["func"], handler["args"])
call remove(l:handlers, index(l:handlers, handler)) call add(found, handler["regex"])
elseif line =~# '^#include\s\+"\S\+"' break
call add(files, matchstr(line, '^#include\s\+"\zs\S\+\ze"'))
endif endif
endfor endfor
endfor endfor
@ -143,11 +147,16 @@ function! s:SearchHeaders(handlers)
catch /E484/ catch /E484/
continue continue
endtry endtry
let lines = filter(lines, 'v:val =~# "#\s*include"')
for handler in s:handlers
if index(found, handler["regex"]) != -1
continue
endif
for line in lines for line in lines
for handler in l:handlers if line =~# handler["regex"]
if line =~# '^#include.*' . handler["regex"]
let includes .= call(handler["func"], handler["args"]) let includes .= call(handler["func"], handler["args"])
call remove(l:handlers, index(l:handlers, handler)) call add(found, handler["regex"])
break
endif endif
endfor endfor
endfor endfor