From 6614e5ef5d60693bd80a6c2aa46e397bb153aedf Mon Sep 17 00:00:00 2001 From: Simon Richter Date: Thu, 30 Jun 2016 11:15:46 -0400 Subject: [PATCH] Eeschema: rewrite loop conditions in SCH_SCREEN::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 753809a247..407ef636b3 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -425,20 +425,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() : testItem->Next() ) { + restart = false; + if( ( item->Type() == SCH_LINE_T ) && ( testItem->Type() == SCH_LINE_T ) ) { SCH_LINE* line = (SCH_LINE*) item; @@ -448,13 +447,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 ) ) @@ -464,17 +459,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(); } } }