Re: NSButton question
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.