Is there a faster way?

Dar Scott dsc at swcp.com
Sun Jun 29 11:46:00 EDT 2003


On Sunday, June 29, 2003, at 10:04 AM, Jan Schenkel wrote:

> In this case, 'repeat for each' might be your friend :
> it usually cuts down on the number of times the engine
> has to go through the variable to pluck data from it.

This is very important when chunks need to be counted from the front or 
back.  With characters, the leaning toward 'repeat for each' applies 
but is less important and solutions that use "repeat with" might be 
considered.  (I believe char positions are calculated directly and 
chars are not counted from the front or back.)

For example (off the top of my head):

function oddChars x
   local accumulation
   repeat with n = 1 to the length of x step 2
      put char n of x after accumulation
   end repeat
   return accumulation
end oddChars

(Does this get the last odd char?)

I'm not sure whether this will compete with 'repeat for each', but I'd 
give it a try.  If the binary file is very large, I'd make x a 
reference variable in the above function.

Tim, if this is a big-endian, little-endian problem in the big picture, 
please mention that.  I'm considering recommending that explicit byte 
order be added to binaryEncode and binaryDecode and would like to hear 
what you are doing to address this.  Also, you might find some help 
with these functions in handling binary files in any case.

Dar scott







More information about the use-livecode mailing list