From 6fd7065d9ebfb9170bdf565d4a9f5195b299ea63 Mon Sep 17 00:00:00 2001 From: Kien N Date: Sat, 10 Sep 2011 17:07:48 +0700 Subject: [PATCH] small performance increase --- autoload/ctrlp.vim | 32 ++++++++++++++++++++++++++------ doc/ctrlp.txt | 8 +++++--- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index d0bb1a09..e136ecbc 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -249,12 +249,14 @@ func! s:GetMatchedItems(items, pats, limit) "{{{ cal map(pats, 'substitute(v:val, "\\\~", "\\\\\\~", "g")') " loop through the patterns for each in pats + " if newitems is small, set it as items to search in if exists('newitems') && len(newitems) < limit - let items = newitems + let items = deepcopy(newitems) + let s:matcheditems = deepcopy(items) endif - if empty(items) + if empty(items) " end here retu exists('newitems') ? newitems : [] - else + else " start here, goes back up if has 2 or more in pats let newitems = [] " loop through the items for item in items @@ -391,7 +393,7 @@ func! s:Renderer(lines) "{{{ cal setline('1', ' == NO MATCHES ==') endif " Remember selected line - if exists('g:CtrlP_cline') + if exists('g:CtrlP_cline') && s:pinput == 2 cal setpos('.', [0, g:CtrlP_cline, 1, 0]) endif endfunc "}}} @@ -399,11 +401,28 @@ endfunc "}}} func! s:UpdateMatches(pat) "{{{ " Delete the buffer's content sil! %d _ - let newpat = s:SplitPattern(a:pat) - let lines = s:GetMatchedItems(s:lines, newpat, s:mxheight) + let items = s:LinesFilter() + let pats = s:SplitPattern(a:pat) + let lines = s:GetMatchedItems(items, pats, s:mxheight) cal s:Renderer(lines) endfunc "}}} +func! s:LinesFilter() "{{{ + " tiny performance increase, but every little bit counts + if exists('g:CtrlP_prompt_prev') + let prt = g:CtrlP_prompt + let prt_prev = g:CtrlP_prompt_prev + let str = prt[0] . prt[1] . prt[2] + let str_prev = prt_prev[0] . prt_prev[1] . prt_prev[2] + endif + if exists('s:matcheditems') && len(s:matcheditems) < s:mxheight + \ && exists('str') && match(str, str_prev) >= 0 + retu s:matcheditems + else + retu s:lines + endif +endfunc "}}} + func! s:BuildPrompt(...) "{{{ let base1 = s:regexp ? 'r' : '>' let base2 = s:byfname ? 'd' : '>' @@ -448,6 +467,7 @@ endfunc func! s:PrtAdd(char) let prt = g:CtrlP_prompt + let g:CtrlP_prompt_prev = deepcopy(g:CtrlP_prompt) let prt[0] = prt[0] . a:char cal s:BuildPrompt() endfunc diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index 23e33903..d049805e 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -51,8 +51,9 @@ setting is from bottom to top: > < *'g:ctrlp_persistent_input'* -Remember the last input string and position of the selection in the match -window: > +Remember the last input string. Set this to 2 to also remember the last +position of the selection in the match window and 0 to completely disable this +feature: > let g:ctrlp_persistent_input = 1 < @@ -352,9 +353,10 @@ CHANGELOG *ctrlp-update-2* Update #2~ + + Extended the behavior of |g:ctrlp_persistent_input| + + New option: |g:ctrlp_dotfiles| + New input format: '..' (section 5.d) + New mapping: . - + New option: |g:ctrlp_dotfiles| + New commands: |:CtrlPCurWD|, |:CtrlPCurFile|, |:CtrlPRoot|