[kgraphviewer-devel] Re: optimize map loops

Milian Wolff mail at milianw.de
Sun Nov 7 23:02:08 CET 2010


On Sunday 07 November 2010 22:11:51 Gaël (aka Kleag) wrote:
> Hi again Millian,
> 
> I now have replaced all (I think) remaining occurrences by iterators.

while this is better, it's not the best you can do :)

--- a/src/part/dotgraph.cpp
+++ b/src/part/dotgraph.cpp
@@ -734,10 +734,10 @@ void DotGraph::removeSubgraphNamed(const QString& 
subgraphName)
 void DotGraph::removeEdge(const QString& id)
 {
   kDebug() << id;
-  QList<QString> edgesKeys = edges().keys();
-  foreach (const QString& eid, edgesKeys)
+  GraphEdgeMap::iterator it = edges().begin();
+  for (; it != edges().end(); it++)
   {
-    GraphEdge* edge = edges()[eid];
+    GraphEdge* edge = it.value();
     if (edge->id() ==id)
     {

Isn't the map storing ID <-> Edge to begin with? If so, use this:

if(GraphEdge* edge = m_edgesMap.value(id, 0)) {
  ...
}

Same for some of the other changes I think.

Thanks and bye
-- 
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/7c5f75b3/attachment.sig 


More information about the kgraphviewer-devel mailing list