Skip to content

Commit

Permalink
small performance increase
Browse files Browse the repository at this point in the history
  • Loading branch information
kien committed Sep 10, 2011
1 parent 7c4669c commit 6fd7065
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
32 changes: 26 additions & 6 deletions autoload/ctrlp.vim
Expand Up @@ -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
Expand Down Expand Up @@ -391,19 +393,36 @@ 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 "}}}

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' : '>'
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions doc/ctrlp.txt
Expand Up @@ -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
<

Expand Down Expand Up @@ -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: <F5>.
+ New option: |g:ctrlp_dotfiles|
+ New commands: |:CtrlPCurWD|,
|:CtrlPCurFile|,
|:CtrlPRoot|
Expand Down

0 comments on commit 6fd7065

Please sign in to comment.