Re: self = [super init], nil?
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