Performance: Cache BOARD::GetMaxClearanceValue

This commit is contained in:
Yon Uriarte 2024-03-03 13:54:46 +00:00 committed by Jon Evans
parent f6cf78fd7c
commit fe1c73ed7c
2 changed files with 22 additions and 3 deletions

View File

@ -80,6 +80,8 @@ BOARD::BOARD() :
m_project( nullptr ),
m_userUnits( EDA_UNITS::MILLIMETRES ),
m_designSettings( new BOARD_DESIGN_SETTINGS( nullptr, "board.design_settings" ) ),
m_deleting( false ),
m_maxClearanceValue( 0 ),
m_NetInfo( this )
{
// A too small value do not allow connecting 2 shapes (i.e. segments) not exactly connected
@ -131,6 +133,8 @@ BOARD::BOARD() :
BOARD::~BOARD()
{
m_deleting = true;
// Untangle group parents before doing any deleting
for( PCB_GROUP* group : m_groups )
{
@ -254,6 +258,8 @@ void BOARD::IncrementTimeStamp()
{
m_timeStamp++;
UpdateMaxClearanceCache();
if( !m_IntersectsAreaCache.empty()
|| !m_EnclosedByAreaCache.empty()
|| !m_IntersectsCourtyardCache.empty()
@ -772,8 +778,12 @@ BOARD_DESIGN_SETTINGS& BOARD::GetDesignSettings() const
}
int BOARD::GetMaxClearanceValue() const
void BOARD::UpdateMaxClearanceCache()
{
// in destructor, useless work
if( m_deleting )
return;
int worstClearance = m_designSettings->GetBiggestClearanceValue();
for( ZONE* zone : m_zones )
@ -793,7 +803,7 @@ int BOARD::GetMaxClearanceValue() const
worstClearance = std::max( worstClearance, zone->GetLocalClearance().value() );
}
return worstClearance;
m_maxClearanceValue = worstClearance;
}

View File

@ -1133,7 +1133,10 @@ public:
* the clearances from board design settings as well as embedded clearances in footprints,
* pads and zones. Includes electrical, physical, hole and edge clearances.
*/
int GetMaxClearanceValue() const;
int GetMaxClearanceValue() const
{
return m_maxClearanceValue;
};
/**
* Map all nets in the given board to nets with the same name (if any) in the destination
@ -1260,6 +1263,9 @@ private:
( l->*aFunc )( std::forward<Args>( args )... );
}
void UpdateMaxClearanceCache();
friend class PCB_EDIT_FRAME;
@ -1314,6 +1320,9 @@ private:
*/
bool m_legacyTeardrops = false;
bool m_deleting; // inside destructor
int m_maxClearanceValue; // cached value
NETINFO_LIST m_NetInfo; // net info list (name, design constraints...
std::vector<BOARD_LISTENER*> m_listeners;