From 9a55567d237f68b497d8fad0dbffa02e63c1146a Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 17 Mar 2022 01:45:37 +0900 Subject: [PATCH 1/3] Optimize s:pathshorten() --- autoload/ctrlp.vim | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 1b6b8c5c..e71f1911 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -1767,11 +1767,16 @@ fu! s:formatline2(ct, key, str) retu s:lineprefix.( cond ? s:pathshorten(str) : str ) endf - -fu! s:pathshorten(str) - retu matchstr(a:str, '^.\{9}').'...' - \ .matchstr(a:str, '.\{'.( s:winw - 16 ).'}$') -endf +if exists('*strchars') && exists('*strcharpart') + fu! s:pathshorten(str) + retu strcharpart(a:str, 0, 9).'...'.strcharpart(a:str, strchars(a:str) - s:winw + 16) + endf +el + fu! s:pathshorten(str) + retu matchstr(a:str, '^.\{9}').'...' + \ .matchstr(a:str, '.\{'.( s:winw - 16 ).'}$') + endf +en fu! s:offset(lines, height) let s:offset = s:mw_order == 'btt' ? ( a:height - s:res_count ) : 0 From 83f1c204d0209f4782aadd22f5f5d34a43e9959e Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 17 Mar 2022 01:46:51 +0900 Subject: [PATCH 2/3] retab --- autoload/ctrlp.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index e71f1911..febdcc93 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -1769,7 +1769,7 @@ endf if exists('*strchars') && exists('*strcharpart') fu! s:pathshorten(str) - retu strcharpart(a:str, 0, 9).'...'.strcharpart(a:str, strchars(a:str) - s:winw + 16) + retu strcharpart(a:str, 0, 9).'...'.strcharpart(a:str, strchars(a:str) - s:winw + 16) endf el fu! s:pathshorten(str) From f75c3291f44f4d0c11257f089475fc3682afb6cb Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 17 Mar 2022 01:57:23 +0900 Subject: [PATCH 3/3] Add small optimizations --- autoload/ctrlp.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index febdcc93..28184465 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -1762,8 +1762,9 @@ fu! s:formatline2(ct, key, str) let str .= printf(' %s', parts[3]) en en + retu s:lineprefix.str en - let cond = a:ct != 'buf' &&s:ispath && ( s:winw - 4 ) < s:strwidth(str) + let cond = s:ispath && ( s:winw - 4 ) < strchars(str) retu s:lineprefix.( cond ? s:pathshorten(str) : str ) endf