diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index fe05596698..44fefe4560 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -747,14 +747,6 @@ void CN_CONNECTIVITY_ALGO::Clear() } - -void CN_CONNECTIVITY_ALGO::ForEachItem( const std::function& aFunc ) -{ - for( auto item : m_itemList ) - aFunc( *item ); -} - - void CN_CONNECTIVITY_ALGO::ForEachAnchor( const std::function& aFunc ) { ForEachItem( [aFunc] ( CN_ITEM& item ) { diff --git a/pcbnew/connectivity/connectivity_algo.h b/pcbnew/connectivity/connectivity_algo.h index 79537b099f..9faab25934 100644 --- a/pcbnew/connectivity/connectivity_algo.h +++ b/pcbnew/connectivity/connectivity_algo.h @@ -248,7 +248,14 @@ public: CN_LIST& ItemList() { return m_itemList; } void ForEachAnchor( const std::function& aFunc ); - void ForEachItem( const std::function& aFunc ); + + template + void ForEachItem( Func&& aFunc ) + { + for( auto&& item : m_itemList ) + aFunc( *item ); + } + void MarkNetAsDirty( int aNet ); void SetProgressReporter( PROGRESS_REPORTER* aReporter ); diff --git a/pcbnew/connectivity/connectivity_data.cpp b/pcbnew/connectivity/connectivity_data.cpp index 3005923ba3..8b019847dc 100644 --- a/pcbnew/connectivity/connectivity_data.cpp +++ b/pcbnew/connectivity/connectivity_data.cpp @@ -383,31 +383,25 @@ const std::vector CONNECTIVITY_DATA::GetConnectedItems( const std::vector CONNECTIVITY_DATA::GetNetItems( int aNetCode, const KICAD_T aTypes[] ) const { - std::set items; - std::vector rv; + std::vector items; + items.reserve( 32 ); - m_connAlgo->ForEachItem( [&items, aNetCode, &aTypes] ( CN_ITEM& aItem ) + std::bitset type_bits; + + for( unsigned int i = 0; aTypes[i] != EOT; ++i ) { - if( aItem.Valid() && ( aItem.Net() == aNetCode ) ) - { - KICAD_T itemType = aItem.Parent()->Type(); + wxASSERT( aTypes[i] < MAX_STRUCT_TYPE_ID ); + type_bits.set( aTypes[i] ); + } - for( int i = 0; aTypes[i] > 0; ++i ) - { - wxASSERT( aTypes[i] < MAX_STRUCT_TYPE_ID ); - - if( itemType == aTypes[i] ) - { - items.insert( aItem.Parent() ); - break; - } - } - } + m_connAlgo->ForEachItem( [&]( CN_ITEM& aItem ) { + if( aItem.Valid() && ( aItem.Net() == aNetCode ) && type_bits[aItem.Parent()->Type()] ) + items.push_back( aItem.Parent() ); } ); - std::copy( items.begin(), items.end(), std::back_inserter( rv ) ); - - return rv; + std::sort( items.begin(), items.end() ); + items.erase( std::unique( items.begin(), items.end() ), items.end() ); + return items; } diff --git a/pcbnew/connectivity/connectivity_items.cpp b/pcbnew/connectivity/connectivity_items.cpp index f45aad97be..b358acf252 100644 --- a/pcbnew/connectivity/connectivity_items.cpp +++ b/pcbnew/connectivity/connectivity_items.cpp @@ -144,15 +144,6 @@ const VECTOR2I CN_ITEM::GetAnchor( int n ) const } -int CN_ITEM::Net() const -{ - if( !m_parent || !m_valid ) - return -1; - - return m_parent->GetNetCode(); -} - - void CN_ITEM::Dump() { printf(" valid: %d, connected: \n", !!Valid()); diff --git a/pcbnew/connectivity/connectivity_items.h b/pcbnew/connectivity/connectivity_items.h index bd3b5f62cd..1d2c828a25 100644 --- a/pcbnew/connectivity/connectivity_items.h +++ b/pcbnew/connectivity/connectivity_items.h @@ -336,7 +336,10 @@ public: virtual int AnchorCount() const; virtual const VECTOR2I GetAnchor( int n ) const; - int Net() const; + int Net() const + { + return ( !m_parent || !m_valid ) ? -1 : m_parent->GetNetCode(); + } }; typedef std::shared_ptr CN_ITEM_PTR;