Performance tuning: reduce the number of globpath calls
This commit is contained in:
parent
5ab2024fbb
commit
8738341ad0
1 changed files with 23 additions and 7 deletions
30
plug.vim
30
plug.vim
|
@ -129,8 +129,10 @@ function! plug#end()
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let keys = keys(g:plugs)
|
let keys = keys(g:plugs)
|
||||||
|
let plugfiles = s:find_plugfiles()
|
||||||
while !empty(keys)
|
while !empty(keys)
|
||||||
let keys = keys(s:extend(keys))
|
" No need to look for Plugfiles more than once
|
||||||
|
let keys = keys(s:extend(keys, plugfiles))
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
if exists('#PlugLOD')
|
if exists('#PlugLOD')
|
||||||
|
@ -321,7 +323,7 @@ function! s:add(force, repo, ...)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:parse_options(arg)
|
function! s:parse_options(arg)
|
||||||
let opts = { 'branch': 'master', 'frozen': 0 }
|
let opts = { 'branch': 'master', 'frozen': 0, 'local': 0 }
|
||||||
if !empty(a:arg)
|
if !empty(a:arg)
|
||||||
let type = type(a:arg)
|
let type = type(a:arg)
|
||||||
if type == s:TYPE.string
|
if type == s:TYPE.string
|
||||||
|
@ -341,7 +343,7 @@ endfunction
|
||||||
function! s:infer_properties(name, repo)
|
function! s:infer_properties(name, repo)
|
||||||
let repo = a:repo
|
let repo = a:repo
|
||||||
if s:is_local_plug(repo)
|
if s:is_local_plug(repo)
|
||||||
let properties = { 'dir': s:dirpath(expand(repo)) }
|
let properties = { 'dir': s:dirpath(expand(repo)), 'local': 1 }
|
||||||
else
|
else
|
||||||
if repo =~ ':'
|
if repo =~ ':'
|
||||||
let uri = repo
|
let uri = repo
|
||||||
|
@ -613,14 +615,28 @@ function! s:update_impl(pull, args) abort
|
||||||
call setline(1, "Updated. Elapsed time: " . split(reltimestr(reltime(st)))[0] . ' sec.')
|
call setline(1, "Updated. Elapsed time: " . split(reltimestr(reltime(st)))[0] . ' sec.')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:extend(names)
|
function! s:find_plugfiles()
|
||||||
|
let plugfiles = {}
|
||||||
|
for pf in split(globpath(g:plug_home, '*/'.s:plug_file), '\n')
|
||||||
|
let plugfiles[split(pf, '[\/]\+')[-2]] = pf
|
||||||
|
endfor
|
||||||
|
return plugfiles
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:extend(names, ...)
|
||||||
let s:extended = {}
|
let s:extended = {}
|
||||||
|
let plugfiles = a:0 > 0 ? a:1 : s:find_plugfiles()
|
||||||
try
|
try
|
||||||
command! -nargs=+ Plug call s:add(0, <args>)
|
command! -nargs=+ Plug call s:add(0, <args>)
|
||||||
for name in a:names
|
for name in a:names
|
||||||
let plugfile = globpath(s:rtp(g:plugs[name]), s:plug_file)
|
let spec = g:plugs[name]
|
||||||
if filereadable(plugfile)
|
if get(spec, 'local', 0)
|
||||||
execute "source ". s:esc(plugfile)
|
let plugfile = globpath(s:rtp(spec), s:plug_file)
|
||||||
|
if filereadable(plugfile)
|
||||||
|
execute 'source '. s:esc(plugfile)
|
||||||
|
endif
|
||||||
|
elseif has_key(plugfiles, name)
|
||||||
|
execute 'source '. s:esc(plugfiles[name])
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
finally
|
finally
|
||||||
|
|
Loading…
Reference in a new issue