On Monday, July 14, 2003, at 03:23 PM, Richard Gaskin wrote:
Actually, that won't work: "repeat for each" requires you to specify a chunk
variable, like this:
repeat for each line tMyLine of tText
doSomething(tMyLine)
end repeat
Why is it so much faster?
When you say:
get line i of tText
...it has to walk through all the characters from the beginning, counting
carriage returns as it goes, until it reaches i number of lines. This
creates a scaling problem: the first time through the loop it's pretty
fast, but by the end it could be traversing hundreds or thousands of lines
each time through. It does this with the most flexible assumption: if
something in the loop changes tText, only this brute-force method will
accurately count lines.
The "repeat for each" form works on a different assumption: in cases where
you know tText won't change during the loop, the engine can afford to keep a
pointer into tText that tells it where it left off. Each time through the
loop it only counts forward from where it last left off to the end of the
next line, so it scales beautifully: each iteration takes almost exactly
the same time as the last.
And with specifying a chunk variable in the repeat statement, the chunk is
already parsed and stored in that var each iteration, ready for use.
--
Richard Gaskin
Well I'll be. This might actually optimize RevBlowfish.
This:
put 1 into ic
put 1 into ix
repeat while ic <= textCryptLength
put char ix to (ix + 3) of cryptThisText into strXL
put char (ix + 4) to (ix + 7) of cryptThisText into strXL
might works as:
repeat for each char tMychunk of cryptThisText step 8
put char 1 to 4 of tMychunk into strXL
put char 5 to 8 of tMychunk into strXR
Does anyone know if "repeat for each char" works with step?
Mark
