[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    RE: Missing the point ?? (KDE speed issues)
From:       <ralsina () kde ! org>
Date:       2002-01-23 19:27:34
[Download RAW message or body]

On Wed, 23 Jan 2002, Schmidt, John wrote:

> Yes, unnecessary instructions could kill the fastest processors.  Something 
> that seems to be used =frequently= (in code here as well) is using some sort
> 
> of method call in the condition of a "for" loop:

[snip]

> Every example I've seen in a text book usually has a simple
> (to evaluate) condition statement.
> 
> for ( int count; variable<constant; count++) 

Here you are comparing references, not integers, so "<" would not work at
all the way you expect it to. Try "==".

> I'm still rather new to C/C++, is this common practice used for 
> readability?


a) end() in a Qt container class is usually very very quick
b) If you ever change the code to modify the container's contents inside
   the loop, the out-of-loop end() breaks. This happens all the time if
   you ever give up control to the Qt event loop inside your for().

   Basically, what was the last element on the container when you enter
   the loop may not be the last element on any following iteration.

c) You are using references here, you are not using integers. That doesn't
   necessarily make any difference, but just in case ;-)

As a side note, if you ever use threads, b) is a hundred times more
true.

In general, it is a bad idea to do things that save little time (and this
is VERY little time) if they are less readable or even possibly less
correct.

Remember the golden rule of optimization: don't sweat the small stuff.

 ("\''/").__..-''"`-. .         Roberto Alsina
 `9_ 9  )   `-. (    ).`-._.`)  ralsina@kde.org
 (_Y_.)' ._   ) `._`.  " -.-'   KDE Developer (MFCH)
  _..`-'_..-_/ /-'_.'           Abeja obrera en Xtech (www.xtech.com.ar)
(l)-'' ((i).' ((!.'             Buenos Aires - Argentina
Futuaris nisi irrisus ridebis. (Carlton, De rerum comoedia)


 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic