TEXTCRUNCHER XTRA HELP: LINGO TIPS FOR INCREASING SPEED | ||
Operations on text chunks are much faster if you put the contents of the field or text member into a string variable and operate on that rather than on the field or text member itself. For example:
on oneMethod SetPosition(0) repeat while firstChar > 0 set firstChar = FindNext(field "someField","cat") if char(firstChar + 3) of field "someField" = " " then ReplaceNext(field "someField","cat","dog") end if end repeat end
on fasterMethod set temp = field "someField" SetPosition(0) repeat while firstChar > 0 set firstChar = FindNext(temp,"cat") if char(firstChar + 3) of temp = " " then ReplaceNext(temp,"cat","dog") end if end repeat put temp into field "someField" end
When you pass a large string variable as the argument to a handler, Lingo has to make a copy of the string variable which can really slow things down. If it is a very large string and you don't have enough memory to make the copy, Director might even crash. In such a case it is faster to store the large string in a global and let the handler operate directly on the global. If you are familiar with behaviors, you can accomplish the same thing by storing the string once as a property variable that you reference from the behavior's handlers.
on oneMethod findString,hugeSearchString if FindFirst(hugeSearchString,findString) > 0 then return TRUE else return FALSE end if end
on fasterSaferMethod findString global hugeSearchString if FindFirst(hugeSearchString,findString) > 0 then return TRUE else return FALSE end if end |