Hi Terry,

Can you use arrays? They aren't necessarily faster, but in this case they might be. Although you have a repeat-for loop, you're still updating a counter to keep track of your second data list. Using arrays just might speed things up, because the engine won't need to count things from the beginning in every loop but can instead read the correct elements from both arrays directly. I suspect this solution will either be slower or just a little fast, but it could be worth a try.

on displayData tRecNum
   --put milliseconds() into tS
   lock screen
   lock messages
   set the uRecNum of me to tRecNum
   put the uCols of me into tCols
   put the uRows of me into tRows
   set the itemDelimiter to tab
   put 1 into tFldNum
   put 1 into tLineNum
   put line tRecNum to tRecNum + tRows - 1 of the uData of me into tData
put line tRecNum to tRecNum + tRows - 1 of the uSelected of me into tSelectedData
   split tData by cr // numeric keys
   split tSelectedData by cr // same numeric keys
   repeat for each line myKey in the keys of tData // use numeric keys
      if tSelectedData[myKey] then
         put "62,117,215"  into tBackColor
         put "255,255,255"  into tForeColor
      else
         put "0,0,0"  into tForeColor
         if myKey mod 2 = 0 then
            put "244,246,250" into tBackColor
         else
            put "255,255,255" into tBackColor
         end if
      end if
      put 1 into fldNum
      repeat for each item tCellData in item 1 to tCols of tData[myKey]
         put tCellData into fld tFldNum of me
         set the backgroundColor of fld tFldNum of me to tBackColor
         set the foregroundColor of fld tFldNum of me to tForeColor
         add 1 to tFldNum
      end repeat
      // add 1 to tLineNum
   end repeat
   unlock messages
   unlock screen
   --put milliseconds() - ts into cd fld "result"
end displayData

You might want to check that this script actually does what you want. I only made a few quick edits..


--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Use Color Converter to convert CMYK, RGB, RAL, XYZ, H.Lab and other colour spaces. http://www.color-converter.com

Buy my new book "Programming LiveCode for the Real Beginner" http://qery.us/3fi

LiveCode on Facebook:
https://www.facebook.com/groups/runrev/

On 3/10/2014 13:15, Terence Heaford wrote:
Mark,

Thanks for your comments.

I am not having a particular problem, just trying to write efficient methods.

I have created my own text table in a group consisting of 6 cols (fields) * 20 
rows (fields) to try and speed up the scrolling when using a DG.

This has worked with a scrolling speed increase of approx. 30% when compared to 
the DG, probably because my table purely uses text and has no need for the 
remaining code that is in the DG.

The most time consuming element is loading all the fields with the data. Here 
is the displayData routine.

Can you see any areas that could me modified to speed it up?

on displayData tRecNum
    --put milliseconds() into tS
    lock screen
    lock messages
    set the uRecNum of me to tRecNum
    put the uCols of me into tCols
    put the uRows of me into tRows
    set the itemDelimiter to tab
    put 1 into tFldNum
    put 1 into tLineNum
    put line tRecNum to tRecNum + tRows - 1 of the uData of me into tData
    put line tRecNum to tRecNum + tRows - 1 of the uSelected of me into 
tSelectedData
    repeat for each line tRecData in tData
       put item 1 to tCols of tRecData into tFldData
       if line tLineNum of tSelectedData = true then
          put "62,117,215"  into tBackColor
          put "255,255,255"  into tForeColor
       else
          put "0,0,0"  into tForeColor
          if tLineNum mod 2 = 0 then
             put "244,246,250" into tBackColor
          else
             put "255,255,255" into tBackColor
          end if
       end if
       repeat for each item tCellData in tFldData
          put tCellData into fld tFldNum of me
          set the backgroundColor of fld tFldNum of me to tBackColor
          set the foregroundColor of fld tFldNum of me to tForeColor
          add 1 to tFldNum
       end repeat
       add 1 to tLineNum
    end repeat
    unlock messages
    unlock screen
       --put milliseconds() - ts into cd fld "result"
end displayData



All the best

Terry


_______________________________________________
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