Re: Deleting last item of a List
Re: Deleting last item of a List
- Subject: Re: Deleting last item of a List
- From: Nigel Garvey <email@hidden>
- Date: Fri, 19 Nov 2004 23:07:46 +0000
On 19/11/2004 at 21:21 my time (GMT), Hanaan Rosenthal wrote:
>On Nov 19, 2004, at 4:00 PM, Nigel Garvey wrote:
>
>> set x to end of myList -- get the last item in the list
>> set x to last item of myList -- ditto
>>
>> (For some reason, the former executes more quickly.)
>The reason why using 'set end of' executes faster is because it creates
>a list with a slightly different use of memory.
Thanks for the amplification , Hanaan. In fact, I was referring to
*getting* the last item in a list. My rough guess for why getting the end
of a list is faster than getting its last item is that AppleScript
doesn't need to check that the last item is actually an 'item'. :-)
Rather in the same way that counting a list is faster than counting its
items.
>The two ways to create a list are:
>1. set theList to theList & newItem
... which of course involves the coercion of newItem to list and then the
concatenation of the lists ...
>2. set end of theList to newItem
>Method 2 will create a list faster, but it will be spread out in
>memory, and therefor will be slower to work with.
>
>The ideal, I believe, is to create a list with method 2 and then use
>the copy command to copy it to another variable, therefore
>consolidating the list items to one place in memory:
I hadn't realised that. Testing it here doesn't show any timing
difference at all between getting the items of a "grown" list and getting
those of list copied from it. But then a simple test script doesn't offer
many opportunities for list fragmentation. :-)
>I am certain that using this tip would save you at least a second or
>two of script execution over your lifetime.
Possibly a couple of days with my 4400. ;-)
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden