← Back to team overview

kicad-developers team mailing list archive

[PATCH 1/5] Rewrite loop conditions in SchematicCleanUp

 

These are a tiny bit more readable, and do not depend on all branches to
correctly advance the loop variable.
---
 eeschema/sch_screen.cpp | 27 +++++++--------------------
 1 file changed, 7 insertions(+), 20 deletions(-)

diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp
index 43610ba..bb3ebe1 100644
--- a/eeschema/sch_screen.cpp
+++ b/eeschema/sch_screen.cpp
@@ -428,20 +428,19 @@ bool SCH_SCREEN::IsTerminalPoint( const wxPoint& aPosition, int aLayer )
 
 bool SCH_SCREEN::SchematicCleanUp()
 {
-    SCH_ITEM* item, * testItem;
     bool      modified = false;
 
-    item = m_drawList.begin();
-
-    for( ; item; item = item->Next() )
+    for( SCH_ITEM* item = m_drawList.begin() ; item; item = item->Next() )
     {
         if( ( item->Type() != SCH_LINE_T ) && ( item->Type() != SCH_JUNCTION_T ) )
             continue;
 
-        testItem = item->Next();
+        bool restart;
 
-        while( testItem )
+        for( SCH_ITEM* testItem = item->Next(); testItem; testItem = restart ? m_drawList.begin() : item->Next() )
         {
+            restart = false;
+
             if( ( item->Type() == SCH_LINE_T ) && ( testItem->Type() == SCH_LINE_T ) )
             {
                 SCH_LINE* line = (SCH_LINE*) item;
@@ -451,13 +450,9 @@ bool SCH_SCREEN::SchematicCleanUp()
                     // Keep the current flags, because the deleted segment can be flagged.
                     item->SetFlags( testItem->GetFlags() );
                     DeleteItem( testItem );
-                    testItem = m_drawList.begin();
+                    restart = true;
                     modified = true;
                 }
-                else
-                {
-                    testItem = testItem->Next();
-                }
             }
             else if ( ( ( item->Type() == SCH_JUNCTION_T )
                       && ( testItem->Type() == SCH_JUNCTION_T ) ) && ( testItem != item ) )
@@ -467,17 +462,9 @@ bool SCH_SCREEN::SchematicCleanUp()
                     // Keep the current flags, because the deleted segment can be flagged.
                     item->SetFlags( testItem->GetFlags() );
                     DeleteItem( testItem );
-                    testItem = m_drawList.begin();
+                    restart = true;
                     modified = true;
                 }
-                else
-                {
-                    testItem = testItem->Next();
-                }
-            }
-            else
-            {
-                testItem = testItem->Next();
             }
         }
     }

Follow ups