Off the top of my head:

split v1 by tab
split v2 by tab
split v3 by tab
split v4 by tab

put the keys of v1 into tKeyList
sort tKeyList ascending numeric

repeat for each line tKey in tKeyList
   put tKey & tab & v1 [tKey] & tab & v2 [tKey] & tab & v3 [tKey] & tab & v4 
[tKey] & cr after tCombined
end repeat

Not sure if this will be faster, but every time you refer to a line of a string 
the engine has to parse out where that line is from the beginning. Parsing 
times will increase exponentially (is that the right term?) the more lines you 
are parsing in both the source strings AND the destination string. 

But arrays are indexed memory locations so the engine knows exactly where every 
bit of text is. And putting something after a string does not have to parse to 
find the end, the engine knows where that is in memory. It might be even faster 
though if you build an array as output and then use the combine command to 
convert it all at once to a string. 

I am assuming of course that splitting does not put lines of text in random 
order in the array. Arrays can be dicey that way. 

Bob S



> On Aug 19, 2022, at 14:09 , Paul Dupuis via use-livecode 
> <use-livecode@lists.runrev.com> wrote:
> 
> I have a set of fields, call them A, B, C, and D. Each has the same number of 
> lines. Each field has different text (per line)
> 
> I need to combine the data - frequently - into a form that look like:
> 
> <i><tab><line i of fld A><tab><line i of fld B><tab><line i of fld 
> C><tab><line i of fld D><cr>
> 
> For the number of lines in the set of fields. Currently I do this as follows:
> 
> put empty into vCombined
> put fld A into v1
> put fld B into v2
> put fld C into v3
> put fld D into v4
> repeat with i=1 to the number of lines in v1
>   put i &tab& line i of v1 &tab& line i of v2 &tab& line i of v3 &tab& line i 
> of v4 into line i of vCombined
> end repeat
> 
> I put the field contents into variable before the loop to combine them as my 
> understanding is variable access is faster than field access in a loop
> 
> My question to the Hivemind is: Is there a noticeably faster way to covert 
> these field to the tab delimited structure as show above than the code above?
> 
> This current takes about 20 seconds for 2000 lines or about a second per 100 
> lines (very roughly, I was not using a timer in my code, just my wristwatch 
> seconds in the IDE debugger between breakpoints)
> 
> Thank you for any pointers in advance,
> 
> Paul Dupuis
> Researchware
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to