On Dec 24, 2009, at 3:16 PM, Sherm Pendley wrote:
> On Thu, Dec 24, 2009 at 5:13 PM, Greg Parker <gpar...@apple.com> wrote:
>> 
>> More precisely, there's exactly one short-circuit check and thus only one 
>> selector value. Under GC, @selector(retain) == @selector(release) == 
>> @selector(autorelease) == @selector(dealloc) == @selector(retainCount). 
>> Happily, `return self` works to implement all of those.
> 
> Just out of curiosity, is that really a short-circuit in the
> message-passing machinery, or are all those selectors simply
> registered to point to the same IMP function? A useless bit of
> knowledge for us end-users, I know, but interesting just the same.

Both. There are an extra two instructions at the start of most flavors of 
objc_msgSend(). That's intended to do nothing fast. The method lookup machinery 
also recognizes that selector value, and hands back a `return self` IMP. That's 
for the benefit of code that looks up IMPs and calls them directly.

The second half was missing at one point during Leopard development. Some code 
was looking up IMPs for -retain and -release. But under GC the methods named 
above share the same selector value, so the runtime handed back the first 
method in the class's method list with that selector. For most classes this is 
the -dealloc implementation. Hilarity ensued.


-- 
Greg Parker     gpar...@apple.com     Runtime Wrangler


_______________________________________________

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