From cf15a1c49312016a4b0fbe5477ad1edb7676af28 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Fri, 28 Feb 2020 23:03:04 -0500 Subject: [PATCH] Cache SCH_SHEET_PATH recursion test results --- eeschema/sch_sheet_path.cpp | 20 +++++++++++++++++--- eeschema/sch_sheet_path.h | 6 ++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 014179e3bf..b37be431a5 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -254,9 +254,13 @@ bool SCH_SHEET_PATH::operator==( const SCH_SHEET_PATH& d1 ) const } -bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName, - const wxString& aDestFileName ) const +bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName ) { + auto pair = std::make_pair( aSrcFileName, aDestFileName ); + + if( m_recursion_test_cache.count( pair ) ) + return m_recursion_test_cache.at( pair ); + wxFileName rootFn = g_RootSheet->GetFileName(); wxFileName srcFn = aSrcFileName; wxFileName destFn = aDestFileName; @@ -270,7 +274,10 @@ bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName, // The source and destination sheet file names cannot be the same. if( srcFn == destFn ) + { + m_recursion_test_cache[pair] = true; return true; + } /// @todo Store sheet file names with full path, either relative to project path /// or absolute path. The current design always assumes subsheet files are @@ -294,7 +301,10 @@ bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName, // The destination sheet file name was not found in the sheet path or the destination // sheet file name is the root sheet so no recursion is possible. if( i >= size() || i == 0 ) + { + m_recursion_test_cache[pair] = false; return false; + } // Walk back up to the root sheet to see if the source file name is already a parent in // the sheet path. If so, recursion will occur. @@ -308,11 +318,15 @@ bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName, cmpFn.MakeAbsolute( rootFn.GetPath() ); if( cmpFn == srcFn ) + { + m_recursion_test_cache[pair] = true; return true; + } } while( i != 0 ); // The source sheet file name is not a parent of the destination sheet file name. + m_recursion_test_cache[pair] = false; return false; } @@ -642,7 +656,7 @@ bool SCH_SHEET_LIST::IsComplexHierarchy() const bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy, - const wxString& aDestFileName ) const + const wxString& aDestFileName ) { wxFileName rootFn = g_RootSheet->GetFileName(); wxFileName destFn = aDestFileName; diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index b2aeed73a4..fd39c54171 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -116,6 +116,8 @@ protected: int m_pageNumber; /// Page numbers are maintained by the sheet load order. + std::map, bool> m_recursion_test_cache; + public: SCH_SHEET_PATH(); @@ -283,7 +285,7 @@ public: * @param aDestFileName is the file name of the destination sheet for \a aSrcFileName. * @return true if \a aFileName will cause recursion in the sheet path. Otherwise false. */ - bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName ) const; + bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName ); bool operator==( const SCH_SHEET_PATH& d1 ) const; @@ -423,7 +425,7 @@ public: * @return true if \a aFileName will cause recursion in the sheet path. Otherwise false. */ bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy, - const wxString& aDestFileName ) const; + const wxString& aDestFileName ); /** * Function FindSheetForScreen