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

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.

  • Follow-Ups:
    • Re: accessor question
      • From: Scott Anguish <email@hidden>
References: 
 >Re: accessor question (From: sinclair44 <email@hidden>)

  • Prev by Date: Re: accessor question
  • Next by Date: Re: NSMailDelivery
  • Previous by thread: Re: accessor question
  • Next by thread: Re: accessor question
  • Index(es):
    • Date
    • Thread