• 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: + initialize docs conflict?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: + initialize docs conflict?


  • Subject: Re: + initialize docs conflict?
  • From: j o a r <email@hidden>
  • Date: Wed, 2 Feb 2005 16:42:02 +0100


On 2005-02-02, at 16.13, Shaun Wexler wrote:

This may belong on the perfoptimization-dev list, but I just wanted to point out some optimizations that should become normal practice. If you need to use a variable retrieved by a message more than once in a method, you should cache it locally:

+ (void)initialize
{
	Class class = [IIButton class];

	if (self == class) {
		[self setCellClass:class];
		... // use class elsewhere
	}
}

Besides what Rick pointed out, I wholeheartedly disagree with your suggested practice.
I would only create a local variable where:
1) it improves my ability to read the code, or
2) it provides an performance advantage that actually matters


#2 is definitively not the generally the case, and especially not in the context of +initialize (which is most of the time only ever run once). I would typically use it when enumerating over a larget number of objects, and in that case also only after evaluating the possible improvements by using a performance tool, like Shark. Another reason to use #2 might be that you happen to *know* (from documentation or benchmarks) that the method returning the value is expensive (it might need to iterate over a list to return the value, or something similar).

j o a r

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

  • Follow-Ups:
    • Re: + initialize docs conflict?
      • From: Shaun Wexler <email@hidden>
References: 
 >Re: + initialize docs conflict? (From: "Buck, Erik (Space Technology)" <email@hidden>)
 >Re: + initialize docs conflict? (From: mmalcolm crawford <email@hidden>)
 >Re: + initialize docs conflict? (From: Ricky Sharp <email@hidden>)
 >Re: + initialize docs conflict? (From: Shaun Wexler <email@hidden>)

  • Prev by Date: Re: + initialize docs conflict?
  • Next by Date: Re: + initialize docs conflict?
  • Previous by thread: Re: + initialize docs conflict?
  • Next by thread: Re: + initialize docs conflict?
  • Index(es):
    • Date
    • Thread