RE: accessor question
RE: accessor question
- Subject: RE: accessor question
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Thu, 27 Feb 2003 16:33:32 -0500
>
It would be faster to do it like this, if you can (how much faster depends
>
on what -recalculate does):
>
>
- (void)setMyValue:(float)aValue
>
{
>
myValue = aValue;
>
needsRecalc = YES;
>
}
>
>
- (float)myValue
>
{
>
if (needsRecalc)
>
[self recalculate];
>
>
return myValue;
>
}
>
This doesn't sound right to me.
First, you are assuming that the only time you use the object is to get its
myValue. There could be a hundred different ivars that are recalculated in
[self recalculate], and the object would give you the wrong value for them
after [self setMyValue] unless you first ask for myValue.
Second, it's no faster. It seems like it would be very slightly slower.
You are merely delaying the [self recalculate], but when it happens it will
take just as long. Plus, you are taking the time to set an extra variable
and perform an extra conditional.
Jonathan
_______________________________________________
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.