Created
September 22, 2011 17:21
-
-
Save skahack/1235392 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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