[kgraphviewer-devel] Re: optimize map loops

Milian Wolff mail at milianw.de
Sun Nov 7 16:26:35 CET 2010


On Sunday 07 November 2010 16:22:10 Milian Wolff wrote:
> Hey Gael,
> 
> Albert reviewed parts of kgraphviewer and spotted things like this:
> 
>   QList<QString> edgesKeys = edges().keys();
>   foreach (const QString& eid, edgesKeys)
>   {
>     GraphEdge* edge = edges()[eid];
> 
> This is like the worst possible way to iterate over maps you can imagine.
> Instead you should write it like this:
> 
>   QMap<QString, GraphEdge*>::const_iterator it = edges().constBegin();
>   while (it != edges().constEnd()) {
>      // use it.value() and it.key() here
>      ++it;
>   }
> 
> Though looking at the sources, one can even rewrite them much simpler, I'll
> commit it, please review it then.

I just tried to push but it failed, Gael - did you enable the hooks?

See also: http://community.kde.org/Sysadmin/GitKdeOrgManual#hooks-enable

My error:
Counting objects: 9, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 551 bytes, done.
Total 5 (delta 4), reused 0 (delta 0)
remote: Auditing commits, please wait ...
remote: ***** NOTICE *****
remote: ** Post commit hooks are DISABLED
remote: ** Push access is restricted to repository admins
remote: ***** NOTICE *****
remote: Poking gitweb for immediate commit URL resolving...
To git at git.kde.org:kgraphviewer
   651d41c..0c126f1  master -> master


-- 
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/kgraphviewer-devel/attachments/20101107/64142165/attachment.sig 


More information about the kgraphviewer-devel mailing list