← Back to team overview

kicad-developers team mailing list archive

[PATCH 2/5] Cache netlist item during ERC

 

This adds a suffix "Idx" to the indexes into the list, and introduces local
copies of the pointers to the objects we are looking at, in order to have a
shorter way of addressing them.
---
 eeschema/dialogs/dialog_erc.cpp | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp
index 37c521c..1d77e43 100644
--- a/eeschema/dialogs/dialog_erc.cpp
+++ b/eeschema/dialogs/dialog_erc.cpp
@@ -492,8 +492,8 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
     // Reset the connection type indicator
     objectsConnectedList->ResetConnectionsType();
 
-    unsigned lastItem;
-    unsigned nextItem = lastItem = 0;
+    unsigned lastItemIdx;
+    unsigned nextItemIdx = lastItemIdx = 0;
     int MinConn    = NOC;
 
     /* The netlist generated by SCH_EDIT_FRAME::BuildNetListBase is sorted
@@ -505,17 +505,19 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
      * pass.
      */
 
-    for( unsigned item = 0; item < objectsConnectedList->size(); item++ )
+    for( unsigned itemIdx = 0; itemIdx < objectsConnectedList->size(); itemIdx++ )
     {
-        if( objectsConnectedList->GetItemNet( lastItem ) !=
-            objectsConnectedList->GetItemNet( item ) )
+        auto item = objectsConnectedList->GetItem( itemIdx );
+        auto lastItem = objectsConnectedList->GetItem( lastItemIdx );
+
+        if( lastItem->GetNet() != item->GetNet() )
         {
             // New net found:
-            MinConn    = NOC;
-            nextItem   = item;
+            MinConn      = NOC;
+            nextItemIdx = itemIdx;
         }
 
-        switch( objectsConnectedList->GetItemType( item ) )
+        switch( item->m_Type )
         {
         // These items do not create erc problems
         case NET_ITEM_UNSPECIFIED:
@@ -535,11 +537,11 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
             // ERC problems when pin sheets do not match hierarchical labels.
             // Each pin sheet must match a hierarchical label
             // Each hierarchical label must match a pin sheet
-            objectsConnectedList->TestforNonOrphanLabel( item, nextItem );
+            objectsConnectedList->TestforNonOrphanLabel( itemIdx, nextItemIdx );
             break;
         case NET_GLOBLABEL:
             if( m_tstUniqueGlobalLabels )
-                objectsConnectedList->TestforNonOrphanLabel( item, nextItem );
+                objectsConnectedList->TestforNonOrphanLabel( itemIdx, nextItemIdx );
             break;
 
         case NET_NOCONNECT:
@@ -547,19 +549,19 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
             // ERC problems when a noconnect symbol is connected to more than one pin.
             MinConn = NET_NC;
 
-            if( objectsConnectedList->CountPinsInNet( nextItem ) > 1 )
-                Diagnose( objectsConnectedList->GetItem( item ), NULL, MinConn, UNC );
+            if( objectsConnectedList->CountPinsInNet( nextItemIdx ) > 1 )
+                Diagnose( item, NULL, MinConn, UNC );
 
             break;
 
         case NET_PIN:
 
             // Look for ERC problems between pins:
-            TestOthersItems( objectsConnectedList.get(), item, nextItem, &MinConn );
+            TestOthersItems( objectsConnectedList.get(), itemIdx, nextItemIdx, &MinConn );
             break;
         }
 
-        lastItem = item;
+        lastItemIdx = itemIdx;
     }
 
     // Test similar labels (i;e. labels which are identical when

Follow ups

References