Only read from cache when necessary
This commit is contained in:
parent
b1a688fc2f
commit
2cedde3400
@ -198,7 +198,7 @@ fu! s:Close()
|
||||
sil! exe 'let &'.key.' = s:glb_'.key
|
||||
en | endfo
|
||||
if exists('s:glb_acd') | let &acd = s:glb_acd | en
|
||||
let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []]
|
||||
let g:ctrlp_lines = []
|
||||
if s:winres[1] >= &lines && s:winres[2] == winnr('$')
|
||||
exe s:winres[0]
|
||||
en
|
||||
@ -233,9 +233,9 @@ fu! ctrlp#reset()
|
||||
endf
|
||||
" * Files {{{1
|
||||
fu! ctrlp#files()
|
||||
let [cafile, g:ctrlp_allfiles] = [ctrlp#utils#cachefile(), []]
|
||||
let cafile = ctrlp#utils#cachefile()
|
||||
if g:ctrlp_newcache || !filereadable(cafile) || !s:caching
|
||||
let lscmd = s:lsCmd()
|
||||
let [lscmd, s:initcwd, g:ctrlp_allfiles] = [s:lsCmd(), s:dyncwd, []]
|
||||
" Get the list of files
|
||||
if empty(lscmd)
|
||||
cal s:GlobPath(s:dyncwd, 0)
|
||||
@ -246,15 +246,16 @@ fu! ctrlp#files()
|
||||
en
|
||||
" Remove base directory
|
||||
cal ctrlp#rmbasedir(g:ctrlp_allfiles)
|
||||
let read_cache = 0
|
||||
if len(g:ctrlp_allfiles) <= s:compare_lim
|
||||
cal sort(g:ctrlp_allfiles, 'ctrlp#complen')
|
||||
en
|
||||
cal s:writecache(cafile)
|
||||
el
|
||||
let g:ctrlp_allfiles = ctrlp#utils#readfile(cafile)
|
||||
let read_cache = 1
|
||||
if !( exists('s:initcwd') && s:initcwd == s:dyncwd )
|
||||
let s:initcwd = s:dyncwd
|
||||
let g:ctrlp_allfiles = ctrlp#utils#readfile(cafile)
|
||||
en
|
||||
en
|
||||
cal s:writecache(read_cache, cafile)
|
||||
retu g:ctrlp_allfiles
|
||||
endf
|
||||
|
||||
@ -1010,7 +1011,7 @@ fu! s:mixedsort(s1, s2)
|
||||
unl! s:mrbs
|
||||
retu cln + ctm * mp_1 + cfn * mp_2 + par * mp_3 + cml * mp_4
|
||||
en
|
||||
let [mp_1, mp_2, mp_3, mp_4] = s:multiplier(cfn, par, cml, 0)
|
||||
let [mp_1, mp_2, mp_3, mp_4] = s:multipliers(cfn, par, cml, 0)
|
||||
retu cln + cfn * mp_1 + par * mp_2 + cml * mp_3
|
||||
en
|
||||
retu cln + cml * 2
|
||||
@ -1545,11 +1546,12 @@ fu! s:mmode()
|
||||
retu matchmodes[s:mfunc]
|
||||
endf
|
||||
" Cache {{{2
|
||||
fu! s:writecache(read_cache, cache_file)
|
||||
if !a:read_cache && ( ( g:ctrlp_newcache || !filereadable(a:cache_file) )
|
||||
\ && s:caching || len(g:ctrlp_allfiles) > s:nocache_lim )
|
||||
fu! s:writecache(cache_file)
|
||||
if ( g:ctrlp_newcache || !filereadable(a:cache_file) ) && s:caching
|
||||
\ || len(g:ctrlp_allfiles) > s:nocache_lim
|
||||
if len(g:ctrlp_allfiles) > s:nocache_lim | let s:caching = 1 | en
|
||||
cal ctrlp#utils#writecache(g:ctrlp_allfiles)
|
||||
let g:ctrlp_newcache = 0
|
||||
en
|
||||
endf
|
||||
|
||||
@ -1567,7 +1569,7 @@ fu! s:insertcache(str)
|
||||
endfo
|
||||
en
|
||||
cal insert(data, str, pos)
|
||||
cal s:writecache(0, ctrlp#utils#cachefile())
|
||||
cal s:writecache(ctrlp#utils#cachefile())
|
||||
endf
|
||||
" Extensions {{{2
|
||||
fu! s:mtype()
|
||||
|
@ -54,20 +54,19 @@ fu! ctrlp#dir#init(...)
|
||||
let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().s:dir_var['sname']
|
||||
let cafile = cadir.ctrlp#utils#lash().ctrlp#utils#cachefile(s:dir_var['sname'])
|
||||
if g:ctrlp_newdir || !filereadable(cafile)
|
||||
let g:ctrlp_alldirs = []
|
||||
let [s:initcwd, g:ctrlp_alldirs] = [s:cwd, []]
|
||||
cal s:globdirs(s:cwd, 0)
|
||||
cal ctrlp#rmbasedir(g:ctrlp_alldirs)
|
||||
let read_cache = 0
|
||||
if len(g:ctrlp_alldirs) <= s:compare_lim
|
||||
cal sort(g:ctrlp_alldirs, 'ctrlp#complen')
|
||||
en
|
||||
el
|
||||
let g:ctrlp_alldirs = ctrlp#utils#readfile(cafile)
|
||||
let read_cache = 1
|
||||
en
|
||||
if !read_cache
|
||||
cal ctrlp#utils#writecache(g:ctrlp_alldirs, cadir, cafile)
|
||||
let g:ctrlp_newdir = 0
|
||||
el
|
||||
if !( exists('s:initcwd') && s:initcwd == s:cwd )
|
||||
let s:initcwd = s:cwd
|
||||
let g:ctrlp_alldirs = ctrlp#utils#readfile(cafile)
|
||||
en
|
||||
en
|
||||
retu g:ctrlp_alldirs
|
||||
endf
|
||||
|
@ -38,7 +38,7 @@ fu! s:getnewmix(cwd, clim)
|
||||
cal ctrlp#mrufiles#refresh('raw')
|
||||
let g:ctrlp_newcache = 1
|
||||
en
|
||||
let g:ctrlp_lines = ctrlp#files()
|
||||
let g:ctrlp_lines = copy(ctrlp#files())
|
||||
cal ctrlp#progress('Mixing...')
|
||||
let mrufs = ctrlp#mrufiles#list('raw')
|
||||
if exists('+ssl') && &ssl
|
||||
|
@ -33,9 +33,9 @@ fu! ctrlp#utils#cachedir()
|
||||
endf
|
||||
|
||||
fu! ctrlp#utils#cachefile(...)
|
||||
let tail = a:0 ? '.'.a:1 : ''
|
||||
let cache_file = substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').tail.'.txt'
|
||||
retu a:0 ? cache_file : s:cache_dir.s:lash(s:cache_dir).cache_file
|
||||
let [tail, dir] = [a:0 == 1 ? '.'.a:1 : '', a:0 == 2 ? a:1 : getcwd()]
|
||||
let cache_file = substitute(dir, '\([\/]\|^\a\zs:\)', '%', 'g').tail.'.txt'
|
||||
retu a:0 == 1 ? cache_file : s:cache_dir.s:lash(s:cache_dir).cache_file
|
||||
endf
|
||||
|
||||
fu! ctrlp#utils#readfile(file)
|
||||
@ -60,9 +60,6 @@ endf
|
||||
fu! ctrlp#utils#writecache(lines, ...)
|
||||
if isdirectory(ctrlp#utils#mkdir(a:0 ? a:1 : s:cache_dir))
|
||||
sil! cal writefile(a:lines, a:0 >= 2 ? a:2 : ctrlp#utils#cachefile())
|
||||
if !a:0
|
||||
let g:ctrlp_newcache = 0
|
||||
en
|
||||
en
|
||||
endf
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user