Setting hidden of lines very slow

hakan at hakan at
Mon Dec 3 09:51:00 EST 2018

The code will not work if you have htmltext containing the text "color=" like:
<p>To set the color you can use color="#fa3b42"</p>

and you can also shave off some milliseconds in the styledText version by using foreach:

repeat for each key aKey in tTextA
      # Check if first run has textcolor set
      put (tTextA[aKey]["runs"][1]["style"]["textcolor"] is empty) \
            into tTextA[aKey]["style"]["hidden"]
 end repeat

For me that is always faster than your clever 'offset("color="…' version.

It is a bit strange though that the foreach always seams to be faster. If we try to sum an array with 100 000 element like:

   put 100000 into tNum
   # Create array with random numbers
   repeat with i = 1 to tNum
      put random(100) into tData[i]
   end repeat

   # Sum array by looping with index
   put the long seconds into tStart
   repeat with i = 1 to tNum
      add tData[i] to tSum
   end repeat
   put the long seconds - tStart into tTime1

   #Sum array by using foreach
   put the long seconds into tStart
   repeat for each key aKey in tData
      add tData[aKey] to tSum2
   end repeat
   put the long seconds - tStart into tTime2
   put tTime1 , tTime2, " ratio : " & tTime1 / tTime2

You will see that the second code is almost three times faster than the first one.

<Lesson>If it isn’t important that you process an indexed array in order foreach is always faster!</lesson>

Happy coding!

On 1 Dec 2018, 15:40 +0100, How to use LiveCode , wrote:
> if offset("color=",L)>0 then put "<p" & L after s
> else put "<p hidden" & L after s

More information about the Use-livecode mailing list