[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: Re: KDE/kdelibs/kdecore
From: Simon Hausmann <hausmann () kde ! org>
Date: 2007-01-14 14:38:24
Message-ID: 200701141538.32666.hausmann () kde ! org
[Download RAW message or body]
On Sunday 14 January 2007 15:07, Thiago Macieira wrote:
> Albert Astals Cid wrote:
> >Add const & to foreach variables so you use the value that is in the
> > container instead of creating a temporal variable and using the copy
> > constructor
>
> Instead, remove the foreach and use iterators.
>
> That improves code performance.
>
> foreach (const Type &varname, list)
> becomes:
> QList<Type>::ConstIterator it = list.constBegin();
> QList<Type>::ConstIterator end = list.constEnd();
> for ( ; it != end; ++it) {
> const Type &varname = *it;
I don't think it is worth the uglification. foreach is too beautiful for
that :)
If you compare the code to which foreach() expands with gcc to a manually
written loop like above you'll notice that the only difference potentially
affecting performance is that foreach() creates a copy of the implicitly
shared container. I think the additional atomic refcount is totally
negligible here.
Simon
[Attachment #3 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic