diff options
author | w0rp <devw0rp@gmail.com> | 2017-11-11 14:26:54 +0000 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-11-11 14:26:54 +0000 |
commit | bac02c9d81356f1cc1f38b598c30c9b46fe21b7b (patch) | |
tree | 2a71e167d98eaddfc5efe5db4512fce0ab22184f /autoload | |
parent | 8c1d6eda81d408de767916c00d20139ddf6fc9c6 (diff) | |
download | ale-bac02c9d81356f1cc1f38b598c30c9b46fe21b7b.zip |
#1095 Cache the sorting of patterns for g:ale_pattern_options
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/pattern_options.vim | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/autoload/ale/pattern_options.vim b/autoload/ale/pattern_options.vim index a55a27f6..e58b8cf2 100644 --- a/autoload/ale/pattern_options.vim +++ b/autoload/ale/pattern_options.vim @@ -1,6 +1,10 @@ " Author: w0rp <devw0rp@gmail.com> " Description: Set options in files based on regex patterns. +" These variables are used to cache the sorting of patterns below. +let s:last_pattern_options = {} +let s:sorted_items = [] + function! s:CmpPatterns(left_item, right_item) abort if a:left_item[0] < a:right_item[0] return -1 @@ -18,13 +22,19 @@ function! ale#pattern_options#SetOptions(buffer) abort return endif + " The items will only be sorted whenever the patterns change. + if g:ale_pattern_options != s:last_pattern_options + let s:last_pattern_options = deepcopy(g:ale_pattern_options) + " The patterns are sorted, so they are applied consistently. + let s:sorted_items = sort( + \ items(g:ale_pattern_options), + \ function('s:CmpPatterns') + \) + endif + let l:filename = expand('#' . a:buffer . ':p') - " The patterns are sorted, so they are applied consistently. - for [l:pattern, l:options] in sort( - \ items(g:ale_pattern_options), - \ function('s:CmpPatterns') - \) + for [l:pattern, l:options] in s:sorted_items if match(l:filename, l:pattern) >= 0 for [l:key, l:value] in items(l:options) call setbufvar(a:buffer, l:key, l:value) |