Review Request: some krazy (and cppcheck) cleanups

Dario Freddi drf54321 at gmail.com
Sun Dec 6 11:52:47 GMT 2009


On Sunday 06 December 2009 11:37:50 Ingo Klöcker wrote:
> On Sunday 06 December 2009, Milian Wolff wrote:
> > On Saturday 05 December 2009 23:53:55 Andrew Coles wrote:
> > > Whilst you're changing loops based on iterators, it's better to
> > > cache the value of foo.end() in a const variable before the start
> > > of the loop:
> > >
> > > {
> > >   std::list<int>::iterator itr = numbers.begin();
> > >   const std::list<int>::iterator itrEnd = numbers.end();
> > >
> > >   for (; itr != itrEnd; ++itr) {
> > >   ...
> > >   }
> > > }
> >
> > Is this really true? I always thought such optimization is not
> > required in compiled languages like Cpp because the compiler does it
> > for you (esp. for const iterators). If not, I might have to optimize
> > some loops I wrote or at least will write future loops like that.
> 
> There's no guarantee that the compiler does it for you, so you should
> always do it. It's even better to use Qt's foreach, boost's foreach or
> std::for_each whenever possible because all of them do the right thing
> so that you don't have to think about it.

Uhm, in this case it should probably be worth it add a krazy check for 
iterators, since there are some times where I can't help out using them 
(iterating maps/hashes).

/me has to optimize a lot of loops with braces as well

> 
> 
> Regards,
> Ingo
> 

-- 
-------------------

Dario Freddi
KDE Developer
GPG Key Signature: 511A9A3B
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20091206/0e482fbc/attachment.sig>


More information about the kde-core-devel mailing list