Can this be done faster ?

Geoff Canyon geoffc at inspiredlogic.com
Fri Jul 21 10:53:33 EDT 2006


On Jul 20, 2006, at 7:27 PM, John Miller wrote:

> put 50 into XX
> put the ticks into timer
> repeat until listXX is empty
>   put line 1 to XX of listXX into listYY
>   delete line 1 to XX of listXX
>   repeat with x = 1 to (number of lines in listYY)
>      doaction to line x of listYY
>   end repeat
> end repeat
> put the ticks - timer

You'd almost certainly get even better performance with repeat for  
each. The problem with any loop where you are repeatedly getting line  
N is that the more lines there are, the longer it takes to get the  
last ones because you have to count through all the previous ones.  
Breaking it up into chunks of 50 (as you did above) improves the  
situation, but doesn't fix it. Throw a large enough list at it and it  
will choke. Repeat for each takes each line in turn, so it never has  
to re-count through the list. A list twice as long with take twice as  
long, no matter how big the lists get.

Here's an example:

repeat for each line L in listXX
   doaction to L
end repeat

If you need to know the line number as you go along, then use this:

put 0 into tLineNumber
repeat for each line L in listXX
   add 1 to tLineNumber
   doaction to L
end repeat



More information about the use-livecode mailing list