mirror of
https://github.com/junegunn/vim-plug.git
synced 2024-12-19 18:47:29 -07:00
Performace tuning: inlining some function calls
This commit is contained in:
parent
300176ba9f
commit
5ab2024fbb
41
plug.vim
41
plug.vim
@ -297,13 +297,15 @@ function! s:add(force, repo, ...)
|
|||||||
|
|
||||||
let exception = ''
|
let exception = ''
|
||||||
try
|
try
|
||||||
let [name, spec] = s:build_plug_spec(a:repo, a:000)
|
let repo = s:trim_trailing_slashes(a:repo)
|
||||||
|
let name = s:extract_name(repo)
|
||||||
if !a:force && has_key(g:plugs, name)
|
if !a:force && has_key(g:plugs, name)
|
||||||
let s:extended[name] = g:plugs[name]
|
let s:extended[name] = g:plugs[name]
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let spec = extend(s:parse_options(a:0 == 1 ? a:1 : {}),
|
||||||
|
\ s:infer_properties(name, repo))
|
||||||
if !a:force
|
if !a:force
|
||||||
let s:extended[name] = spec
|
let s:extended[name] = spec
|
||||||
endif
|
endif
|
||||||
@ -318,24 +320,14 @@ function! s:add(force, repo, ...)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:build_plug_spec(repo, opts)
|
function! s:parse_options(arg)
|
||||||
try
|
|
||||||
let [name, properties] = s:infer_properties(a:repo)
|
|
||||||
let spec = extend(s:parse_options(a:opts), properties)
|
|
||||||
return [name, spec]
|
|
||||||
catch
|
|
||||||
throw v:exception
|
|
||||||
endtry
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:parse_options(args)
|
|
||||||
let opts = { 'branch': 'master', 'frozen': 0 }
|
let opts = { 'branch': 'master', 'frozen': 0 }
|
||||||
if !empty(a:args)
|
if !empty(a:arg)
|
||||||
let arg = a:args[0]
|
let type = type(a:arg)
|
||||||
if type(arg) == s:TYPE.string
|
if type == s:TYPE.string
|
||||||
let opts.branch = arg
|
let opts.branch = a:arg
|
||||||
elseif type(arg) == s:TYPE.dict
|
elseif type == s:TYPE.dict
|
||||||
call extend(opts, arg)
|
call extend(opts, a:arg)
|
||||||
if has_key(opts, 'tag')
|
if has_key(opts, 'tag')
|
||||||
let opts.branch = remove(opts, 'tag')
|
let opts.branch = remove(opts, 'tag')
|
||||||
endif
|
endif
|
||||||
@ -346,9 +338,8 @@ function! s:parse_options(args)
|
|||||||
return opts
|
return opts
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:infer_properties(repo)
|
function! s:infer_properties(name, repo)
|
||||||
let repo = s:trim_ending_slash(a:repo)
|
let repo = a:repo
|
||||||
let name = s:extract_name(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)) }
|
||||||
else
|
else
|
||||||
@ -360,13 +351,13 @@ function! s:infer_properties(repo)
|
|||||||
endif
|
endif
|
||||||
let uri = 'https://git:@github.com/' . repo . '.git'
|
let uri = 'https://git:@github.com/' . repo . '.git'
|
||||||
endif
|
endif
|
||||||
let dir = s:dirpath( fnamemodify(join([g:plug_home, name], '/'), ':p') )
|
let dir = s:dirpath( fnamemodify(join([g:plug_home, a:name], '/'), ':p') )
|
||||||
let properties = { 'dir': dir, 'uri': uri }
|
let properties = { 'dir': dir, 'uri': uri }
|
||||||
endif
|
endif
|
||||||
return [name, properties]
|
return properties
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:trim_ending_slash(str)
|
function! s:trim_trailing_slashes(str)
|
||||||
return substitute(a:str, '[/\\]*$', '', '')
|
return substitute(a:str, '[/\\]*$', '', '')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user