Connectivity optimizations

Don't copy the recursion test cache when copy-constructing
SCH_SHEET_PATHs as it's not needed in connectivity

Fix a few places that were copying unnecessarily
This commit is contained in:
Jon Evans 2020-07-08 17:42:05 -04:00
parent 741481591e
commit 282fcd5f3c
4 changed files with 37 additions and 5 deletions

View File

@ -424,7 +424,7 @@ void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnco
} }
void CONNECTION_GRAPH::updateItemConnectivity( SCH_SHEET_PATH aSheet, void CONNECTION_GRAPH::updateItemConnectivity( const SCH_SHEET_PATH& aSheet,
const std::vector<SCH_ITEM*>& aItemList ) const std::vector<SCH_ITEM*>& aItemList )
{ {
std::unordered_map< wxPoint, std::vector<SCH_ITEM*> > connection_map; std::unordered_map< wxPoint, std::vector<SCH_ITEM*> > connection_map;
@ -1807,8 +1807,8 @@ void CONNECTION_GRAPH::propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph )
} }
std::shared_ptr<SCH_CONNECTION> CONNECTION_GRAPH::getDefaultConnection( SCH_ITEM* aItem, std::shared_ptr<SCH_CONNECTION>
SCH_SHEET_PATH aSheet ) CONNECTION_GRAPH::getDefaultConnection( SCH_ITEM* aItem, const SCH_SHEET_PATH& aSheet )
{ {
auto c = std::shared_ptr<SCH_CONNECTION>( nullptr ); auto c = std::shared_ptr<SCH_CONNECTION>( nullptr );

View File

@ -366,7 +366,7 @@ private:
* @param aSheet is the path to the sheet of all items in the list * @param aSheet is the path to the sheet of all items in the list
* @param aItemList is a list of items to consider * @param aItemList is a list of items to consider
*/ */
void updateItemConnectivity( SCH_SHEET_PATH aSheet, void updateItemConnectivity( const SCH_SHEET_PATH& aSheet,
const std::vector<SCH_ITEM*>& aItemList ); const std::vector<SCH_ITEM*>& aItemList );
/** /**
@ -425,7 +425,8 @@ private:
* @param aItem is an item that can generate a connection name * @param aItem is an item that can generate a connection name
* @return a connection generated from the item, or nullptr if item is not valid * @return a connection generated from the item, or nullptr if item is not valid
*/ */
std::shared_ptr<SCH_CONNECTION> getDefaultConnection( SCH_ITEM* aItem, SCH_SHEET_PATH aSheet ); std::shared_ptr<SCH_CONNECTION> getDefaultConnection( SCH_ITEM* aItem,
const SCH_SHEET_PATH& aSheet );
void recacheSubgraphName( CONNECTION_SUBGRAPH* aSubgraph, const wxString& aOldName ); void recacheSubgraphName( CONNECTION_SUBGRAPH* aSubgraph, const wxString& aOldName );

View File

@ -103,6 +103,30 @@ SCH_SHEET_PATH::SCH_SHEET_PATH()
} }
SCH_SHEET_PATH::SCH_SHEET_PATH( const SCH_SHEET_PATH& aOther )
{
initFromOther( aOther );
}
SCH_SHEET_PATH& SCH_SHEET_PATH::operator=( const SCH_SHEET_PATH& aOther )
{
initFromOther( aOther );
return *this;
}
void SCH_SHEET_PATH::initFromOther( const SCH_SHEET_PATH& aOther )
{
m_sheets = aOther.m_sheets;
m_pageNumber = aOther.m_pageNumber;
m_current_hash = aOther.m_current_hash;
// Note: don't copy m_recursion_test_cache as it is slow and we want SCH_SHEET_PATHS to be
// very fast to construct for use in the connectivity algorithm.
}
void SCH_SHEET_PATH::Rehash() void SCH_SHEET_PATH::Rehash()
{ {
m_current_hash = 0; m_current_hash = 0;

View File

@ -132,6 +132,10 @@ protected:
public: public:
SCH_SHEET_PATH(); SCH_SHEET_PATH();
SCH_SHEET_PATH( const SCH_SHEET_PATH& aOther );
SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& aOther );
/// Forwarded method from std::vector /// Forwarded method from std::vector
SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); } SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); }
@ -304,6 +308,9 @@ public:
bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; } bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
private:
void initFromOther( const SCH_SHEET_PATH& aOther );
}; };