Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ?
Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ?
- Subject: Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ?
- From: Aurélien Hugelé <email@hidden>
- Date: Thu, 23 Dec 2004 14:21:52 +0100
hi list !
i'm tuning my application and since a long time ago, i noticed that
using indexOfObjectIdenticalTo: is far (i mean something like 1000 x
faster on 20 000 items) faster that indexOfObject:
IMO indexOfObject is just Olog(n) because it needs full traversal of
the array if the searched object is the last one.
but indexOfObjectIdenticalTo: use probably the same algorithm except
that the equality test is faster (address equality instead of (slower?)
isEqual: message)
but i think the speed difference would not be so large. I suppose that
in fact, NSArray use an internal structure to link an object address to
its index in the array...
Am i totally wrong ? is it "normal" that a "==" test is 1000 times
faster than isEqual: ?
in Apple documentation, they show that isEqual: should be implemented
like this :
-(void)isEqual:(id)anObject {
if(anObject == self)
return YES;
if( ![anObject isKindOfClass:[self class])
return NO;
return [self isEqualTo_PLACE_HERE_YOUR_OBJECT_:anObject]; //
specialized isEqual, depends of the object internals, logic etc...
}
if all cocoa is implemented like that the difference between isEqual:
and " == " should be quite minor (messaging overhead only)
what's your opinion ?
thanks
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden