• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Two Questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two Questions


  • Subject: Re: Two Questions
  • From: "Serge Belleudy-d'Espinose" <email@hidden>
  • Date: Wed, 14 Feb 2001 15:21:03 +0100

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:


on remove_from_list(xItem, xList)

set xList2 to {}

repeat with xListItem in xList
copy xListItem's contents to xListItem

if xListItem  xItem then ,
set xList2's end to xListItem

end repeat

return xList2

end remove_from_list


Works, slowly. Then another solution based on TIDs


on remove_from_list (xItem, xList)

set {oldTID, AppleScript's text item delimiters} to +;
{AppleScript's text item delimiters, return}

set xList to "" & xList's items

set AppleScript's text item delimiters to xItem
set xList to xList's text items

set AppleScript's text item delimiters to oldTID
set xList to "" & xList's items

set AppleScript's text item delimiters to (return & return)
set xList to (xList's text items)

set AppleScript's text item delimiters to return
set xList to ("" & xList's items)'s text items

set AppleScript's text item delimiters to oldTID

return xList

end remove_from_list

(watch for +; as continuation char)

To my surprise, despite all the string manipulations this one proved constantly 2x faster.

I've been scripting for one year now. My main concern is not only 'how to do it' but also 'how to do it FAST', and I'm increasingly using the power of TIDs.


Serge

__ __ __
_ \///\/ _ I N S T I T U T | Serge Belleudy-d'Espinose - IJM
\///\/// J A C Q U E S | 2 place Jussieu - 75251 Paris Cedex 05
_///\///\_ M O N O D | m@il : email@hidden
__/\///\__ Service Informatique | WWW : http://www.ijm.jussieu.fr/


  • Follow-Ups:
    • Re: Two Questions
      • From: Chris Nebel <email@hidden>
    • Re: Two Questions
      • From: Paul Berkowitz <email@hidden>
References: 
 >Two Questions (From: Byron Peterson <email@hidden>)

  • Prev by Date: AS to database: MacSQL Monitor release
  • Next by Date: Re: Choose a file dialog box?
  • Previous by thread: Re: Two Questions - RemoveListItem(x, theList)
  • Next by thread: Re: Two Questions
  • Index(es):
    • Date
    • Thread