Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8587789

Browse files
committed
Make folding much faster in some cases
Cache the results of Is_opening_folding once per change so it doesn'tloop over the same lines multiple times unnecessarily.
1 parentd113cff commit8587789

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

‎autoload/pymode/folding.vim

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ endfunction "}}}
216216

217217
function!s:Is_opening_folding(lnum)"{{{
218218
" Helper function to see if docstring is opening or closing
219+
220+
" Cache the result so the loop runs only once per change
221+
ifget(b:,'fold_changenr',-1)==changenr()
222+
returnb:fold_cache[a:lnum]"If odd then it is an opening
223+
else
224+
letb:fold_changenr=changenr()
225+
letb:fold_cache= []
226+
endif
227+
219228
let number_of_folding=0" To be analized if odd/even to inform if it is opening or closing.
220229
let has_open_docstring=0" To inform is already has an open docstring.
221230
let extra_docstrings=0" To help skipping ''' and""" which are not docstrings
@@ -224,7 +233,9 @@ function! s:Is_opening_folding(lnum) "{{{
224233
" not just triple quotes (that could be a regular string).
225234
"
226235
" Iterater over all lines from the start until current line (inclusive)
227-
foriinrange(1,a:lnum)
236+
foriinrange(1,line('$'))
237+
calladd(b:fold_cache, number_of_folding%2)
238+
228239
let i_line=getline(i)
229240

230241
if i_line=~s:doc_line_regex
@@ -255,11 +266,9 @@ function! s:Is_opening_folding(lnum) "{{{
255266
endif
256267
endfor
257268

258-
iffmod(number_of_folding,2)==1"If odd then it is an opening
259-
return1
260-
else
261-
return0
262-
endif
269+
calladd(b:fold_cache, number_of_folding%2)
270+
271+
returnb:fold_cache[a:lnum]
263272
endfunction"}}}
264273

265274
" vim:fdm=marker:fdl=0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp