1 Dec 2003 16:41
Re: Calling a function from a :s command (weird results)
Klaus Bosau <kbosau <at> web.de>
2003-12-01 15:41:30 GMT
2003-12-01 15:41:30 GMT
On Mon, 1 Dec 2003, Benji Fisher wrote:
> [...]
>
> I assume that this worked when the InvertString() function was
> first posted to the list, but broken by a later patch. The oldest
> version of vim that I have lying around is 6.1.400. Does anyone with
> an older version get different results?
(I recently upgraded to 6.2, so I can't answer your question.) Just for
those who are interested.. Preben was indeed right, InvertString()
turned out to be about twice as fast as a comparable solution based on a
:while loop.
For
function! InvertString(str)
let inverted = ''
let n = strlen(a:str) - 1
while n >= 0
let inverted = inverted . a:str[n]
let n = n - 1
endwhile
return inverted
endfunction
and
let n = 3000
while n > 0
let x = InvertString('abcdefghijklmnopqrstuvwxyz')
let n = n - 1
endwhile
I got 10 and 5 seconds..
Klaus
RSS Feed