From 282fcd5f3c348b9b7b0bbd0fc2bb7fdbb5cdd926 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 8 Jul 2020 17:42:05 -0400 Subject: [PATCH] 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 --- eeschema/connection_graph.cpp | 6 +++--- eeschema/connection_graph.h | 5 +++-- eeschema/sch_sheet_path.cpp | 24 ++++++++++++++++++++++++ eeschema/sch_sheet_path.h | 7 +++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index e144e5b9d8..4c11a460d8 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -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& aItemList ) { std::unordered_map< wxPoint, std::vector > connection_map; @@ -1807,8 +1807,8 @@ void CONNECTION_GRAPH::propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph ) } -std::shared_ptr CONNECTION_GRAPH::getDefaultConnection( SCH_ITEM* aItem, - SCH_SHEET_PATH aSheet ) +std::shared_ptr +CONNECTION_GRAPH::getDefaultConnection( SCH_ITEM* aItem, const SCH_SHEET_PATH& aSheet ) { auto c = std::shared_ptr( nullptr ); diff --git a/eeschema/connection_graph.h b/eeschema/connection_graph.h index 8ac0af601d..4dc9c372d5 100644 --- a/eeschema/connection_graph.h +++ b/eeschema/connection_graph.h @@ -366,7 +366,7 @@ private: * @param aSheet is the path to the sheet of all items in the list * @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& aItemList ); /** @@ -425,7 +425,8 @@ private: * @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 */ - std::shared_ptr getDefaultConnection( SCH_ITEM* aItem, SCH_SHEET_PATH aSheet ); + std::shared_ptr getDefaultConnection( SCH_ITEM* aItem, + const SCH_SHEET_PATH& aSheet ); void recacheSubgraphName( CONNECTION_SUBGRAPH* aSubgraph, const wxString& aOldName ); diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index a2a7d6c8aa..472c6cb66d 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -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() { m_current_hash = 0; diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index 20b1fbda06..14d7f847fc 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -132,6 +132,10 @@ protected: public: 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 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; } +private: + + void initFromOther( const SCH_SHEET_PATH& aOther ); };