commit bf4591c5d82bdcb47ee55290f13e85da81cd947e
parent 9af083a6d13b7d86f94f43de18d42b6e212f8dbe
Author: Phil Runninger <PhilRunninger@users.noreply.github.com>
Date: Tue, 12 Jun 2018 11:31:03 -0400
Merge pull request #851 from mnussbaum/decrease_startup_time
Decrease startup-time by avoiding linear-time iteration over key mappings
Diffstat:
1 file changed, 16 insertions(+), 22 deletions(-)
diff --git a/lib/nerdtree/key_map.vim b/lib/nerdtree/key_map.vim
@@ -3,18 +3,23 @@
let s:KeyMap = {}
let g:NERDTreeKeyMap = s:KeyMap
-"FUNCTION: KeyMap.All() {{{1
-function! s:KeyMap.All()
-
- if !exists('s:keyMaps')
- let s:keyMaps = []
+"FUNCTION: KeyMap._all() {{{1
+function! s:KeyMap._all()
+ if !exists("s:keyMaps")
+ let s:keyMaps = {}
endif
- call sort(s:keyMaps, s:KeyMap.Compare, s:KeyMap)
-
return s:keyMaps
endfunction
+"FUNCTION: KeyMap.All() {{{1
+function! s:KeyMap.All()
+ let sortedKeyMaps = values(s:KeyMap._all())
+ call sort(sortedKeyMaps, s:KeyMap.Compare, s:KeyMap)
+
+ return sortedKeyMaps
+endfunction
+
"FUNCTION: KeyMap.Compare(keyMap1, keyMap2) {{{1
function! s:KeyMap.Compare(keyMap1, keyMap2)
@@ -31,17 +36,12 @@ endfunction
"FUNCTION: KeyMap.FindFor(key, scope) {{{1
function! s:KeyMap.FindFor(key, scope)
- for i in s:KeyMap.All()
- if i.key ==# a:key && i.scope ==# a:scope
- return i
- endif
- endfor
- return {}
+ return get(s:KeyMap._all(), a:key . a:scope, {})
endfunction
"FUNCTION: KeyMap.BindAll() {{{1
function! s:KeyMap.BindAll()
- for i in s:KeyMap.All()
+ for i in values(s:KeyMap._all())
call i.bind()
endfor
endfunction
@@ -67,12 +67,7 @@ endfunction
"FUNCTION: KeyMap.Remove(key, scope) {{{1
function! s:KeyMap.Remove(key, scope)
- let maps = s:KeyMap.All()
- for i in range(len(maps))
- if maps[i].key ==# a:key && maps[i].scope ==# a:scope
- return remove(maps, i)
- endif
- endfor
+ return remove(s:keyMaps, a:key . a:scope)
endfunction
"FUNCTION: KeyMap.invoke() {{{1
@@ -170,8 +165,7 @@ endfunction
"FUNCTION: KeyMap.Add(keymap) {{{1
function! s:KeyMap.Add(keymap)
- call s:KeyMap.Remove(a:keymap.key, a:keymap.scope)
- call add(s:KeyMap.All(), a:keymap)
+ let s:keyMaps[a:keymap.key . a:keymap.scope] = a:keymap
endfunction
" vim: set sw=4 sts=4 et fdm=marker: