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

List:       kde-devel
Subject:    Re: [KDE4] foreach
From:       Michael Pyne <pynm0001 () unf ! edu>
Date:       2005-08-05 22:54:21
Message-ID: 200508051854.25148.pynm0001 () unf ! edu
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


On Friday 05 August 2005 16:44, Gary Cramblitt wrote:

> It appears that pre-increment is still preferred over post-increment?, i.e.

Yes, but that's because it's a C++ language issue.  pre-increment avoids 
creation of a temporary iterator object which is usually unnecessary.

> but is this better?
>
>     QHash<int, PooledFilterMgr*>::iterator it = m_pooledFilterMgrs.begin();
>     QHash<int, PooledFilterMgr*>::iterator itEnd =
> m_pooledFilterMgrs.end(); while (it != itEnd) {
> 	// do something
>         ++it;
>     }

It is better for any container that doesn't cache the value of end(), only 
problem is that I forget which ones actually can cache it.  So it's generally 
safer to use it if you're worried about performance.

> and of course const_iterator is preferred if you're not going to modify the
> container.

Also don't forget to use constEnd() and constBegin() instead of end() and 
begin(), since it is more efficient for some containers.

Regards,
 - Michael Pyne

[Attachment #5 (application/pgp-signature)]

 =

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscrib=
e <<


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

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