On 19/08/2022 23:32, Mark Wieder via use-livecode wrote:

It is indeed faster. Here's what I came up with. I'm not sure why 2000 lines of text in four fields should take that long, I came up with

original code: 320 ms
array version: 21 ms

   put empty into vCombined
   put fld "A" into v1
   put fld "B" into v2
   put fld "C" into v3
   put fld "D" into v4
   split v1 by cr
   split v2 by cr
   split v3 by cr
   split v4 by cr
   put 1 into i
   repeat for each element tLine in v1
      put i&tab&v1[i]&tab&v2[i]&tab&v3[i]&tab&v4[i]&tab&cr after vCombined
      add 1 to i
   end repeat

which is already quick enough that any further improvement is mainly academic.

But for the record:

"repeat for each line " is very efficient for a single variable, o you can avoid one of the four 'split's, and use the line variable to count your loop.

   --   split v1 by cr
   split v2 by cr
   split v3 by cr
   split v4 by cr
   put 1 into i
   repeat for each line tLine in v1
      put i&tab& tLine &tab& v2[i] &tab& v3[i] &tab& v4[i] & cr after vCombined
      add 1 to i
   end repeat

to trim about another 15% off the time (for my sample data, 24ms down to 20ms.)

(and if you know that one of the four fields typically contains much more text (i.e. longer lines) than the others, you would choose it to not be split).

Alex.



_______________________________________________
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