Watson, Christopher wrote

> I'm looking for ANY ways to optimize this "new" handler, without having to
> resort to TextCruncher or any other Xtra.


I game I'm working on uses various 'scripts' (strings) which need to be
tokenised and processed by the game. I did some tests trying to work out
ways of optimising a handler that's quite similar to yours.

As Irv pointed out, putting the delimiters into a list will help (quicker
than parsing through a string with each pass at the data), but most
surprising thing I found that a brute force repeat through the string was by
far the quickest approach (quicker than using offset then repeating through
the possible delimiters).

Modifying the code slightly to match your handler, something like this

on new me, dataStr, delimList
  myTokens = []
  --
  dataLength = dataStr.length
  if dataLength = 0 then return me
  numDelims = delimList.count
  chunkStart = 1
  repeat with i = 1 to dataLength
    thisChar = dataStr.char[i]
    if delimList.getOne(thischar) then
      mytokens.append(dataStr.char[chunkStart..(i-1)])
      -- add the token itself (if required)
      -- mytokens.append(dataStr.char[i])
      chunkStart = i+1
    end if
  end repeat
  return me
end

-- note that this assumes that the delimiters are single chars, and are case
sensitive. Also, in my case, I was tokenising many strings, but they were
relatively short (< 256 chars) - so the speed improvements I found may not
be true in your case.

Another thing - if its preferable to use the offset/repeat through possible
delimiters approach that you have adopted, then the order of delimiters
makes a (mildly) significant difference on the speed if you use the - if
possible, put the most common delimiters at the start of the list.



Luke

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to