Skip to content

Commit

Permalink
Made list#unique about 5 times faster using filter().
Browse files Browse the repository at this point in the history
  • Loading branch information
tarmack committed Sep 7, 2011
1 parent 2cfd515 commit 9cabfbd
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions list.vim
Expand Up @@ -6,18 +6,9 @@
" Remove duplicate values from {list} in-place (preserves order).

function! xolox#misc#list#unique(list)
let index = 0
while index < len(a:list)
let value = a:list[index]
let match = index(a:list, value, index+1)
if match >= 0
call remove(a:list, match)
else
let index += 1
endif
unlet value
endwhile
return a:list
call reverse(a:list)
call filter(a:list, 'count(a:list, v:val) == 1')
return reverse(a:list)
endfunction

" Binary insertion (more efficient than calling sort() after each insertion).
Expand Down

0 comments on commit 9cabfbd

Please sign in to comment.