kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #25159
[PATCH] 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 20a18b9..ff20f20 100644
--- a/eeschema/sch_screen.cpp
+++ b/eeschema/sch_screen.cpp
@@ -426,20 +426,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;
@@ -449,13 +448,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 ) )
@@ -465,17 +460,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