> good performance when we write vimscript.
I'm not sure there's a bible of good performance, but in-built functions
that operate on larger swaths may be faster
> 2- Retrieving and writin data from the 1rst hash => 7 seconds
>
> the func is doing that :
>
> for l:key in keys(s:hash)
> let l:line = substitute
> (l:lineToChange,"TO_SUBSTITUTE_WITH_KEY",l:key,"g")
> let l:line = substitute(l:line,"TO_SUBSTITUTE_WITH_KEY2",s:hash
> [l:key].key2,"")
> let l:line = substitute(l:line,"TO_SUBSTITUTE_WITH_KEY3",s:hash
> [l:key].key3,"")
> exec 'norm o' . l:line
> endfor
>
> Can I reduce time ?
I'm not sure what exactly you're trying to achieve here -- mostly the
source of the l:lineToChange -- is this from some larger loop? The
reason it's confusing is that after you've gone through the loop once,
I'd expect that TO_SUB_WITH_KEY is no longer in the string, so
subsequent passes through the loop look like they're just appending the
same line (which, btw, I'd perform with
put=line
instead of via normal mode.)
My first thought would be to do fewer substitutes, which could be done
if your hashes are nested, so you have a double-dereferencing.
Something like
:%s/TSWK1\|TSWK2\|TSWK3/\=s:hash[submatch(0)]/g
or, if you have a bunch of keys, you might be able to do something like
:let @/=join(keys(s:hash), '\|')
:%s//\=s:hash[submatch[0]]/g
(you might have to escape the keys if there are funky regexp
metacharacter values in the hash keys)
-tim
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment