Skip to content

Instantly share code, notes, and snippets.

@skahack
Created September 22, 2011 17:21
Show Gist options
  • Select an option

  • Save skahack/1235392 to your computer and use it in GitHub Desktop.

Select an option

Save skahack/1235392 to your computer and use it in GitHub Desktop.
function! s:hd2str(hd)
" a:hd is a list because to avoid copying the value.
" Old routine.
let start1 = reltime()
let _ = join(map(split(a:hd[0], '..\zs'), 'v:val == "00" ? "" : eval(''"\x'' . v:val . ''"'')'), '')
echomsg '1:'.reltimestr(reltime(start1))
" To use nr2char(), change encoding option.
" nr2char(255) => "\xc3\xbf" (utf8)
" nr2char(255) => "\xff" (latin1)
"
" This routine is 4x faster.
let start2 = reltime()
let _ = substitute(a:hd[0], '..',
\ '\=submatch(0)=="00"?"":eval(''"\x''.submatch(0).''"'')', 'g')
echomsg '2:'.reltimestr(reltime(start2))
return _
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment