Suggestions for speeding up code
Suggestions for speeding up code
- Subject: Suggestions for speeding up code
- From: James Burns <email@hidden>
- Date: Tue, 25 Feb 2003 16:26:31 -0500
Hello:
This list has been very helpful since I started reintroducing myself to
Applescript, and I was wondering if i could impose just one more time.
I've been writing a program in AppleScript Studio (with everyone's kind
help) and am at the point where I'm trying to optimize my code for
speed. It seems that the following handler takes the most time (3 or 4
seconds, roughly) to read a file, and extract some stuff from it. The
file is a text file with the following format:
...
keyWord value
keyWord value
keyWord value
keyWord value
...
Some of the values are numbers, some can be full paths for files or
directories. I want to extract the value that follows the keyword.
Here's how I'm going about it (be gentle, please):
(Prior to this handler I've opened the file and tested it it contained
some text to see if it was set up right. The global "output" contains
the file contents...)
on extractStuff()
log "Started extractStuff handler"
set FirstFrame to "FirstFrame" -- these are the text string that are
being searched for
set LastFrame to "LastFrame" -- and the variables I need them stuck
into
set FrameStep to "FrameStep"
set stuffToGet to {FirstFrame, LastFrame, FrameStep} --array of what
to search file for
repeat with currentItem from 1 to length of stuffToGet -- step through
items of stuffToGet
set searchWord to item currentItem of stuffToGet
try
set AppleScript's text item delimiters to return -- Check out lines
of file
set i to text items of output -- for each line
repeat with foundString in i -- repeat loop, looking for searchWord
if foundString contains searchWord then -- if successful
set AppleScript's text item delimiters to " "
set cleaned to (text items 2 thru -1 of foundString) as string --
remove searchWord
-- assign value to variable
set item currentItem of stuffToGet to cleaned
exit repeat
end if
end repeat
set AppleScript's text item delimiters to oldDelims
on error what
set AppleScript's text item delimiters to oldDelims
display dialog "Sorry. " & what
end try
end repeat
-- at this point I have the values in an array (ok, list...) called
stuffToGet
set FirstFrame to item 1 of stuffToGet -- this is kludgy, but I
decided to brute force these variables...
set LastFrame to item 2 of stuffToGet
set FrameStep to item 3 of stuffToGet
return
end extractStuff
Thanks in advance for your help.
-----
James Burns
http://www.jamesburnsdesign.com
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.