On May 8, 2010, at 8:28 AM, James Bucanek <subscri...@gloaming.com> 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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to