[haiku-commits] Re: haiku: hrev44066 - src/apps/deskbar

  • From: "Adrien Destugues" <pulkomandy@xxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 24 Apr 2012 19:11:24 +0200

Le Tue, 24 Apr 2012 18:52:51 +0200, Rene Gollent <anevilyak@xxxxxxxxx> a écrit:


On Mon, Apr 23, 2012 at 11:53 PM,  <jscipione@xxxxxxxxx> wrote:
 * Save CountItems() into a variable outside the loop so that it only
   gets called once (micro-optimization/best-practice).

For future reference, this kind of optimization is pointless, the
compiler's smart enough to notice this and eliminate the redundant
call implicitly. No need to make the code less readable.

Is it ?
The compiler is able to inline calls to stuff like BString::Length, which returns a cached value, but not BString::CountChars, which actually loops through the string and might have side effects.

In Haiku code, usually Count*() methods are performing such complex operations (a loop counting or so), and I don't think these are optimized away. On the other hand, Get*Count() or Size(), Length(), and so on methods just return a cached value, and these are easily inlined and optimized.

--
Adrien.


Other related posts: