Permalink
Browse files

refactor KeyMap so we dont use index() on an array of objects

Dont do `remove(array_of_prototype_obs, index(...)))`. In the past this
has been found to cause seg faults when the objects get large.
  • Loading branch information...
1 parent 6782ec0 commit 53bc77644c8149ae995918b9d6f544cc31813346 @scrooloose committed Jan 11, 2012
Showing with 10 additions and 5 deletions.
  1. +10 −5 plugin/NERD_tree.vim
View
@@ -520,6 +520,15 @@ function! s:KeyMap.bind()
exec 'nnoremap <buffer> <silent> '. mapkey . premap . ':call <SID>KeyMap_Invoke("'. self.key .'")<cr>'
endfunction
+"FUNCTION: KeyMap.Remove(key, scope) {{{3
+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
+endfunction
"FUNCTION: KeyMap.invoke() {{{3
"Call the KeyMaps callback function
function! s:KeyMap.invoke(...)
@@ -606,11 +615,7 @@ endfunction
"FUNCTION: KeyMap.Add(keymap) {{{3
function! s:KeyMap.Add(keymap)
- let oldmap = s:KeyMap.FindFor(a:keymap.key, a:keymap.scope)
- if !empty(oldmap)
- call remove(s:KeyMap.All(), index(s:KeyMap.All(), oldmap))
- endif
-
+ call s:KeyMap.Remove(a:keymap.key, a:keymap.scope)
call add(s:KeyMap.All(), a:keymap)
endfunction

0 comments on commit 53bc776

Please sign in to comment.