• 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: self = [super init], nil?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: self = [super init], nil?


  • Subject: Re: self = [super init], nil?
  • From: Kyle Sluder <email@hidden>
  • Date: Sat, 8 May 2010 08:48:41 -0700

On May 8, 2010, at 8:28 AM, James Bucanek <email@hidden> wrote:

I'd like to point out that this is one of those counterintuitive cases where more code is less.

The code

   self = [super init];
   if (self!=nil)
       ...

produces fewer machine instructions than

   if ([super init]!=nil)
       ...

Weird, huh?

It might produce less code, it might not. If you're operating at the ObjC level of abstraction and worrying about the codegen of self= [super init], your priorities are out of order.



The compiler can save the instructions needed to preserve |self| before calling [super init] and restoring it afterwards. Anyway, I've disassembled this on several architectures and the code produced by the preferred pattern is shorter, and therefor more efficient, than trying to take a shortcut.

Since you'd better be assigning self anyway, self doesn't need to be preserved past the call to [super init].


--Kyle Sluder
_______________________________________________

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: self = [super init], nil?
      • From: James Bucanek <email@hidden>
References: 
 >Re: self = [super init], nil? (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: self = [super init], nil?
  • Next by Date: NSImage and NSImageView questions
  • Previous by thread: Re: self = [super init], nil?
  • Next by thread: Re: self = [super init], nil?
  • Index(es):
    • Date
    • Thread