which is faster for searching?

Bob Sneidar bobsneidar at iotecdigital.com
Thu Aug 28 17:24:09 EDT 2014


Repeat for each has been optimized to run faster than other forms of repeat. Use whenever you can. One word of caution though: Do NOT change the value of what you are repeating. (Whatever comes after “in”.) I am pretty sure you should not alter the value returned (the variable after "each <token>”). 

The reason for all this is that to optimize the repeat loop, the engine makes one pass through the data, and creates an index of pointers to the delimiters. If you modify the data, the OS may (and probably will) do some memory shuffling and the pointers will no longer be valid. What you return can be bits and pieces of the original data scrambled like eggs, or random bits of what is now in that memory space. Ick! 

ex. repeat for each line pLine in pData. Don’t alter pLine or pData inside the repeat control structure. 

Bob S


On Jun 17, 2014, at 07:22 , larry at significantplanet.org wrote:

> I have a large variable containing about 3000 lines of data - each line about 100 characters.
> 
> I want to search through the variable and find all the lines that contain a specified string
> 
> Should I use (repeatedly) "lineoffset...", or should I use "repeat for each line..."  or maybe some other faster way?
> 
> Or with only 3000 lines of data, does it even matter?
> 
> TIA
> Larry
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list