From 327ba4c415dd35d926e0c2438adc9aa8b2269a02 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Fri, 3 Jan 2014 19:48:16 +0200 Subject: [PATCH] Optimise loclist.filter(). --- plugin/syntastic/loclist.vim | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/plugin/syntastic/loclist.vim b/plugin/syntastic/loclist.vim index f4b664f0..306ff97e 100644 --- a/plugin/syntastic/loclist.vim +++ b/plugin/syntastic/loclist.vim @@ -126,22 +126,10 @@ endfunction " "Note that all comparisons are done with ==? function! g:SyntasticLoclist.filter(filters) - let rv = [] - - for error in self._rawLoclist - let passes_filters = 1 - for key in keys(a:filters) - if get(error, key, '') !=? a:filters[key] - let passes_filters = 0 - break - endif - endfor - - if passes_filters - call add(rv, error) - endif - endfor - return rv + let conditions = values(map(copy(a:filters), 's:translate(v:key, v:val)')) + let filter = len(conditions) == 1 ? + \ conditions[0] : join(map(conditions, '"(" . v:val . ")"'), ' && ') + return filter(copy(self._rawLoclist), filter) endfunction function! g:SyntasticLoclist.setloclist() @@ -192,4 +180,10 @@ function! g:SyntasticLoclistHide() silent! lclose endfunction +" Private functions {{{1 + +function! s:translate(key, val) + return 'get(v:val, ' . string(a:key) . ', "") ==? ' . string(a:val) +endfunction + " vim: set sw=4 sts=4 et fdm=marker: