Simplify name caching
We don't need two functions to get driver names. The map should be mutable to allow updates when needed. C++17 gives some extra syntactic sugar for map manipulation
This commit is contained in:
parent
a83313c4ab
commit
420eceecbb
|
@ -161,8 +161,8 @@ bool CONNECTION_SUBGRAPH::ResolveDrivers( bool aCheckMultipleDrivers )
|
|||
return false;
|
||||
}
|
||||
|
||||
wxString a_name = GetNameForDriver( a );
|
||||
wxString b_name = GetNameForDriver( b );
|
||||
const wxString& a_name = GetNameForDriver( a );
|
||||
const wxString& b_name = GetNameForDriver( b );
|
||||
bool a_lowQualityName = a_name.Contains( "-Pad" );
|
||||
bool b_lowQualityName = b_name.Contains( "-Pad" );
|
||||
|
||||
|
@ -204,7 +204,7 @@ bool CONNECTION_SUBGRAPH::ResolveDrivers( bool aCheckMultipleDrivers )
|
|||
{
|
||||
// First check if all the candidates are actually the same
|
||||
bool same = true;
|
||||
wxString first = GetNameForDriver( candidates[0] );
|
||||
const wxString& first = GetNameForDriver( candidates[0] );
|
||||
SCH_ITEM* second_item = nullptr;
|
||||
|
||||
for( unsigned i = 1; i < candidates.size(); i++ )
|
||||
|
@ -305,27 +305,11 @@ wxString CONNECTION_SUBGRAPH::driverName( SCH_ITEM* aItem ) const
|
|||
}
|
||||
|
||||
|
||||
const wxString& CONNECTION_SUBGRAPH::GetNameForDriver( SCH_ITEM* aItem )
|
||||
const wxString& CONNECTION_SUBGRAPH::GetNameForDriver( SCH_ITEM* aItem ) const
|
||||
{
|
||||
auto it = m_driver_name_cache.find( aItem );
|
||||
auto [it, success] = m_driver_name_cache.try_emplace( aItem, driverName( aItem ) );
|
||||
|
||||
if( it != m_driver_name_cache.end() )
|
||||
return it->second;
|
||||
|
||||
m_driver_name_cache.emplace( aItem, driverName( aItem ) );
|
||||
|
||||
return m_driver_name_cache.at( aItem );
|
||||
}
|
||||
|
||||
|
||||
const wxString CONNECTION_SUBGRAPH::GetNameForDriver( SCH_ITEM* aItem ) const
|
||||
{
|
||||
auto it = m_driver_name_cache.find( aItem );
|
||||
|
||||
if( it != m_driver_name_cache.end() )
|
||||
return it->second;
|
||||
|
||||
return driverName( aItem );
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1488,7 +1472,7 @@ void CONNECTION_GRAPH::buildConnectionGraph( std::function<void( SCH_ITEM* )>* a
|
|||
if( driver == subgraph->m_driver )
|
||||
continue;
|
||||
|
||||
wxString secondary_name = subgraph->GetNameForDriver( driver );
|
||||
const wxString& secondary_name = subgraph->GetNameForDriver( driver );
|
||||
|
||||
if( secondary_name == subgraph->m_driver_connection->Name() )
|
||||
continue;
|
||||
|
@ -2472,8 +2456,8 @@ bool CONNECTION_GRAPH::ercCheckMultipleDrivers( const CONNECTION_SUBGRAPH* aSubg
|
|||
static_cast<SCH_PIN*>( primary )->GetTransformedPosition() :
|
||||
primary->GetPosition();
|
||||
|
||||
wxString primaryName = aSubgraph->GetNameForDriver( primary );
|
||||
wxString secondaryName = aSubgraph->GetNameForDriver( secondary );
|
||||
const wxString& primaryName = aSubgraph->GetNameForDriver( primary );
|
||||
const wxString& secondaryName = aSubgraph->GetNameForDriver( secondary );
|
||||
|
||||
wxString msg = wxString::Format( _( "Both %s and %s are attached to the same "
|
||||
"items; %s will be used in the netlist" ),
|
||||
|
@ -2502,8 +2486,8 @@ bool CONNECTION_GRAPH::ercCheckMultipleDrivers( const CONNECTION_SUBGRAPH* aSubg
|
|||
|| ( driver->Type() == SCH_PIN_T
|
||||
&& static_cast<SCH_PIN*>( driver )->IsPowerConnection() ) )
|
||||
{
|
||||
wxString primaryName = aSubgraph->GetNameForDriver( aSubgraph->m_driver );
|
||||
wxString secondaryName = aSubgraph->GetNameForDriver( driver );
|
||||
const wxString& primaryName = aSubgraph->GetNameForDriver( aSubgraph->m_driver );
|
||||
const wxString& secondaryName = aSubgraph->GetNameForDriver( driver );
|
||||
|
||||
if( primaryName == secondaryName )
|
||||
continue;
|
||||
|
|
|
@ -112,9 +112,7 @@ public:
|
|||
std::vector<SCH_ITEM*> GetBusLabels() const;
|
||||
|
||||
/// Returns the candidate net name for a driver
|
||||
const wxString& GetNameForDriver( SCH_ITEM* aItem );
|
||||
|
||||
const wxString GetNameForDriver( SCH_ITEM* aItem ) const;
|
||||
const wxString& GetNameForDriver( SCH_ITEM* aItem ) const;
|
||||
|
||||
const wxString GetNetclassForDriver( SCH_ITEM* aItem ) const;
|
||||
|
||||
|
@ -226,7 +224,7 @@ public:
|
|||
CONNECTION_SUBGRAPH* m_hier_parent;
|
||||
|
||||
/// A cache of escaped netnames from schematic items
|
||||
std::unordered_map<SCH_ITEM*, wxString> m_driver_name_cache;
|
||||
mutable std::unordered_map<SCH_ITEM*, wxString> m_driver_name_cache;
|
||||
|
||||
/**
|
||||
* Stores the primary driver for the multiple drivers ERC check. This is the chosen driver
|
||||
|
|
Loading…
Reference in New Issue