• 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
Is checking -count worth it?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is checking -count worth it?


  • Subject: Is checking -count worth it?
  • From: Steve Cronin <email@hidden>
  • Date: Wed, 23 Jul 2008 23:15:57 -0500

Folks;

I'm really trying to learn how to write smart fast code.
Code that takes maximum advantage of all of the battle-tested intelligence built into Cocoa/ObjC2.
Now days with the "halo" and the "JesusPhone", I personally smell an excellent book opportunity... But enough chit-chat.


I have a mutable array, M. I want to remove an object, O, from M; O might not be in M.
M which is being constantly diminished could become empty.


Is this code worth it?
if ([M count]>0) [M removeObject:O];

OR should I just do
[M remove O];

I assume that I can't write better code than the removeObject's use of -indexOfObject to determine the existence/location of O.
So there I get 'best performance' for free by just getting out of the way and letting Cocoa do its thing.


Is the only way to really tell to test?
Or is there a deeper insight that makes the choice clear?

Steve

_______________________________________________

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


  • Follow-Ups:
    • Re: Is checking -count worth it?
      • From: Jens Alfke <email@hidden>
    • Re: Is checking -count worth it?
      • From: Phil <email@hidden>
    • Re: Is checking -count worth it?
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: master-detail: binding array controller to the attribute of selection of master array controller
  • Next by Date: Re: how to correctly set knob/thumb proportion and scroller orientation in NSScroller
  • Previous by thread: Re: how to correctly set knob/thumb proportion and scroller orientation in NSScroller
  • Next by thread: Re: Is checking -count worth it?
  • Index(es):
    • Date
    • Thread