From cc776f71a9e57f84a773c46fb8e344c2a5e35121 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 12 Oct 2018 05:54:21 -0700 Subject: [PATCH] pcbnew: Code cleanup Moving functions to std:: algorithms where feasible to reduce the code burden. --- pcbnew/connectivity_algo.cpp | 9 ++------- pcbnew/connectivity_data.cpp | 30 +++++------------------------- pcbnew/connectivity_data.h | 1 - 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/pcbnew/connectivity_algo.cpp b/pcbnew/connectivity_algo.cpp index d68c7abae0..ef58d16d36 100644 --- a/pcbnew/connectivity_algo.cpp +++ b/pcbnew/connectivity_algo.cpp @@ -82,13 +82,8 @@ bool CN_CLUSTER::Contains( const CN_ITEM* aItem ) bool CN_CLUSTER::Contains( const BOARD_CONNECTED_ITEM* aItem ) { - for( auto item : m_items ) - { - if( item->Valid() && item->Parent() == aItem ) - return true; - } - - return false; + return std::find_if( m_items.begin(), m_items.end(), [ &aItem ] ( const CN_ITEM* item ) + { return item->Valid() && item->Parent() == aItem; } ) != m_items.end(); } diff --git a/pcbnew/connectivity_data.cpp b/pcbnew/connectivity_data.cpp index a968737b3f..497445870b 100644 --- a/pcbnew/connectivity_data.cpp +++ b/pcbnew/connectivity_data.cpp @@ -27,6 +27,7 @@ #endif #include +#include #include #include @@ -237,34 +238,13 @@ void CONNECTIVITY_DATA::FindIsolatedCopperIslands( std::vectorFindIsolatedCopperIslands( aZones ); } -int CONNECTIVITY_DATA::countRelevantItems( const std::vector& aItems ) -{ - int n = 0; - - for( const auto item : aItems ) - { - switch( item->Type() ) - { - case PCB_TRACE_T: - case PCB_PAD_T: - case PCB_ZONE_AREA_T: - case PCB_MODULE_T: - case PCB_VIA_T: - n++; - break; - - default: - break; - } - } - - return n; -} - void CONNECTIVITY_DATA::ComputeDynamicRatsnest( const std::vector& aItems ) { - if( countRelevantItems( aItems ) == 0 ) + if( std::none_of( aItems.begin(), aItems.end(), []( const BOARD_ITEM* aItem ) + { return( aItem->Type() == PCB_TRACE_T || aItem->Type() == PCB_PAD_T || + aItem->Type() == PCB_ZONE_AREA_T || aItem->Type() == PCB_MODULE_T || + aItem->Type() == PCB_VIA_T ); } ) ) { m_dynamicRatsnest.clear(); return ; diff --git a/pcbnew/connectivity_data.h b/pcbnew/connectivity_data.h index 3ffbfdffef..041861ff51 100644 --- a/pcbnew/connectivity_data.h +++ b/pcbnew/connectivity_data.h @@ -243,7 +243,6 @@ public: private: - int countRelevantItems( const std::vector& aItems ); void updateRatsnest(); void addRatsnestCluster( const std::shared_ptr& aCluster );