Re: Two Questions
Re: Two Questions
- Subject: Re: Two Questions
- From: Chris Nebel <email@hidden>
- Date: Wed, 14 Feb 2001 12:25:29 -0800
- Organization: Apple Computer, Inc.
Serge Belleudy-d'Espinose wrote:
>
At 13:13 -0700 11/02/01, Byron Peterson wrote:
>
>
>What is the fastest way to remove an item from a large list (the list I9m
>
>working with has about 3000 items in it). The item I need to remove is in
>
>the middle of the list and it isn9t the same item every time?
>
>
Ok, now that everyone answered, what if someone wants to remove an item knowing only its content, not its index?
>
>
First, a solution that would seem obvious:
>
>
...
>
>
>
Works, slowly. Then another solution based on TIDs
>
>
...
>
>
>
To my surprise, despite all the string manipulations this one proved constantly 2x faster.
Beware that the latter TID-based solution only works correctly if the item you're looking for and all the list items are strings. Anything that's not a string
will be turned into one in the result list, and if the thing you're looking for isn't a string, it won't find it. Additionally, any sub-lists will be
flattened and turned into individual items.
The first solution is slower, but will always preserve the list items in their original form. (Well, mostly. It will break sharing relationships -- the value
will be the same, but it's not shared any more.) Text item delimiters are very powerful, but they can't do everything.
--Chris Nebel
AppleScript Engineering