Re: speeding up list manipulations?
Re: speeding up list manipulations?
- Subject: Re: speeding up list manipulations?
- From: has <email@hidden>
- Date: Fri, 3 May 2002 12:38:06 +0100
Jim Johnson wrote:
>
Currently I'm using a run handler which calls several other handlers:
>
>
on run
>
verifyCatalog()
>
creatOriginalList()
>
removeIllegalExtensions()
>
removeIllegalCharacters()
>
removeExcessWhitespace()
>
checkForDuplicatesAndIncrementAsNecessary()
>
end run
>
>
but what I'm doing seems too
>
complicated (at least to me!) to implement that particular scheme
Don't worry - it's not. Although: you might want to try modifying your
existing code to remove some of its current complexity first...
--
I'm assuming that each of the above handlers iterates through the entire
list performing a single operation on each list item. This is okay, though
an alternate design would have handlers that operate on a simple string
rather than a list of strings. All you do then is pass each filename string
in turn through each of the handlers:
--------------
on run
repeat with eachItem in theList
--[remember: eachItem is a reference to the object,
-- not the object itself - see ASLG p256-8 for info]
firstOperation(eachItem's contents)
secondOperation(result)
thirdOperation(result)
set eachItem's contents to result -- put modified string back into
list [1]
end repeat
end run
--[1] (or whatever else you want to do with the result)
--------------
This should make for a cleaner, simpler, more logical design. Plus, instead
of having to worry about multiple repeat loops, you only have one to deal
with.
--
>
As I figured out the individual handler algorithms, I strung them
>
together to implement the full desired functionality.
This is good practice: write each handler to do a single, complete
function. Test and debug it in isolation, and once you're happy add it into
the main program.
>
Questions:
>
>
1. Should I abstract the original filename list with an 'a reference to'
>
structure before I start modifying it?
You mean do something like:
set realList to {.....}
set theList to a reference to realList
[...]
repeat with eachItem in theList
[...]
end repeat
If you like. If you need more speed then the my/its keyword method tends to
be a bit faster, but the reference trick is equally efficient. And either
will give a major speed improvement over your current approach.
>
2. Should I combine the separate handlers into a unified run handler?
Not unless you want a huge splurge of hard-to-read, hard-to-maintain code
at the end of the day. The only time I'd consider doing that myself is if I
absolutely had to squeeze every last drop of performance out of a script
and I'd already optimised everything else to death. However, the time
saving made from removing calls to handlers is pretty minimal and it does
make for some pretty honking code, so it's rarely a worthwhile tradeoff.
If you mean it as: "Can I solve problems I'm having with the current design
by chucking everything together?" then the answer is: "Yes, but only at the
cost of introducing other design flaws." There's often more than one
solution to a problem, so I'd suggest looking for a better one before you
resort to something as ugly as this. (Hint: I already suggested one.;)
>
Any suggestions welcome
Well, hope this helps.
>
(Including, but not limited to, "Buy a clue!")
Not at all. When things seem to complicated, sometimes all you need is to
rework the problem a little.:)
has
--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
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.