Deleting Data Woefully Slow

Brian Yennie briany at qldlearning.com
Wed Mar 24 22:13:33 EDT 2010


Mark,

This seems highly data-dependent and contrary to logic to me. In my tests:

put line 1 to -2 of tData into tData1
delete line -1 of tData
delete last line of tData

All perform about twice as fast as using "repeat for each". The first was about 10% faster than the next two, which makes sense as it would only be one seek and one copy. The in-place operations would require a seek, a copy, and resizing the original variable. Of course if you end up copying back to the original variable somewhere, it should be very close to the same.

"repeat for each" is asking the engine to find every line ending in the text which would necessarily take much longer and get worse with scale, no?

> And on reading the code yet another time, there's enough fuzzy stuff
> in there to make me discount most of it without rewriting.
> Nonetheless, the conclusions are fairly solid, and the fastest way to
> delete the last line of a variable turns out to be the surprising
> 
>   put empty into tData1
>   put 1 into x
>   put the number of lines in tData into tHowMany
>   repeat for each line tLine in tData
>       put tLine & cr after tData1
>       add 1 to x
>       if x is tHowMany then
>           exit repeat
>       end if
>   end repeat
> 
> -- 
> -Mark Wieder
> mwieder at ahsoftware.net



More information about the use-livecode mailing list