• 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: NSButton question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSButton question


  • Subject: Re: NSButton question
  • From: Simon Stapleton <email@hidden>
  • Date: Sun, 11 Aug 2002 12:59:41 +0200

On Saturday, August 10, 2002, at 02:23 , Ondra Cada wrote:


On Saturday, August 10, 2002, at 10:15 , Simon Stapleton wrote:

Another side note: In Objective-C, we have no method overloading. Thus,
-isEqual: takes (id) as its parameter type, and must, in effect, route the query to a more specialised routine depending on the types of the compared objects. Those classes in Foundation requiring specialist handling of -isEqual: (Strings, Arrays, etc) have specialist handlers - -isEqualToString:, -isEqualToArray: etc, which are faster to use when you know the types you're comparing.

It's slightly different. Right, isEqual is somewhat slower than isEqualToString et comp, but the reason is *not* in "routing to a more specialised routine". The sole difference is in the implementation -- isEqual checks explicitly for a proper class:

@implementation NSString ... // roughly, the actual implementation would differ
...
-(BOOL)isEqual:o {
if (![o isKindOfClass:[NSString class]]) return NO; // THIS is what makes it slower
return _someInternalTestOfEquality(self,o);
}
-(BOOL)isEqualToString:(NSString*)s {
return _someInternalTestOfEquality(self,o);
}

D'oh! Of course. My bad.

The dispatch is just as quick in both cases though.

Indeed, if it's written this way. Not having access to Apple's code, though...

I was thinking the code might look more like

- (BOOL) isEqual: (id) thing {
if ([thing respondsToSelector:@selector(isEqualToString:)])
return [thing isEqualToString:self];
return [super isEqual:thing];
}

<Simon wanders off to look at the GNUStep source, just for kicks>

--
PGP Key Id : 0x50D0698D
--
Your mouse has moved. You must restart Windows NT for this change to be recognised.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >Re: NSButton question (From: Ondra Cada <email@hidden>)

  • Prev by Date: STOP notification problem
  • Next by Date: Re: FTPClient Beta Released - Please test
  • Previous by thread: Re: NSButton question
  • Next by thread: AddressBook property
  • Index(es):
    • Date
    • Thread