Re: NSMutableArray Adding, Sorting and Removing?
Re: NSMutableArray Adding, Sorting and Removing?
- Subject: Re: NSMutableArray Adding, Sorting and Removing?
- From: Quincey Morris <email@hidden>
- Date: Sun, 07 Aug 2011 23:26:17 -0700
On Aug 7, 2011, at 23:09 , Kevin Bracey wrote:
> My question is would it be more efficient to sort the array so the next action becomes the Last object of the array and remove it from the top instead of the bottom?
>
> Or is this all so efficient it make no real difference.
It's not a question so much of efficiency as noticeability -- almost certainly the difference isn't going to be noticeable by any practical standard.
However, since you have an (apparently) arbitrary choice between sorting the "next" operation to the start or the end of the array, put it at the end. It's not hard to imagine that the implementation would shuffle elements down if you remove the first, so you may as well assume that's what happens.
Putting the "next" operation at the end also has the very small beneficial side-effect of letting you use 'lastObject' to get it, which (unlike 'objectAtIndex:0') doesn't crash if the array is empty. Thus, the source code is probably conciser and clearer, all other things being equal.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden