Is there a faster way?

T. R. Ponn alptex2 at orwell.net
Sun Jun 29 15:08:01 EDT 2003


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.
>
Thanks, but I forgot to mention I tried that...and surprisingly, it ran 
slower (about 27 seconds for that file):

  if char 1 of memBank="0" then put "false" into toggle else put "true" 
into toggle
  repeat for each char thisChar in fileContents
    if toggle = false then put thisChar after bank0 else put thisChar 
after bank1
    put not toggle into toggle
  end repeat


Dar Scott wrote:

> 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

This feature (I think) is only available starting with with rev 2.  I've 
got my hands full with implementing this app and updating myself from HC 
to Rev 1.1.1.  I can't wait to try it on Rev 2, but I don't want to 
change horses in mid-stream...I may get wet! ;-)

>
>
> 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.


BINGO, Dar!  That's exactly what I'm trying to do.  16b as 
8b...big-endian, little-endian.  I haven't yet figured out how to apply 
the binEncode/binDecode function to this.  Sure wish there was a 
way...it would have to be faster than this.

Best Regards,

Tim Ponn




More information about the use-livecode mailing list