Re: Faster List Checking
Re: Faster List Checking
- Subject: Re: Faster List Checking
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 28 May 2003 14:41:10 -0700
On 5/28/03 2:15 PM, "Andrew Oliver" <email@hidden> wrote:
>
Also, the line:
>
>
> repeat with i from 1 to (count text items in errorlist)
>
>
Can be optimized to:
>
>
> set numItems to count text items in errorList
>
> repeat with I from 1 to numItems
>
>
In the original form, the script will calculate the 'count text items in
>
errorlist' each time it goes through the loop.
>
By precalculating the number of items in the list you save time.
>
You can only use this technique when you know the list won't change. If
>
you're adding or subtracting items from the list you need to recalculate the
>
number of items in the list on each iteration, but in your script there's no
>
need.
This is in fact not the case. It counts before the repeat loop and not
during. If in fact you _do_ delete or remove anything from the list, it will
error when i turns out to be larger than the last remaining item index, plus
you will have skipped some items en route. (What does get recalculated is
'item i of errorList' since it is within the repeat loop. What does not get
recalculated is ' count text items in errorList' which is outside the loop.)
Hence the recommendation to always work backwards if deleting items
dynamically from a list.
--
Paul Berkowitz
_______________________________________________
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.