Review Request: some krazy (and cppcheck) cleanups

Milian Wolff mail at milianw.de
Sun Dec 6 01:48:08 GMT 2009


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.

-- 
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- 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/0a917f5e/attachment.sig>


More information about the kde-core-devel mailing list