Cache SCH_SHEET_PATH recursion test results

This commit is contained in:
Jon Evans 2020-02-28 23:03:04 -05:00
parent f4f43f51c8
commit cf15a1c493
2 changed files with 21 additions and 5 deletions

View File

@ -254,9 +254,13 @@ bool SCH_SHEET_PATH::operator==( const SCH_SHEET_PATH& d1 ) const
} }
bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName, bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName )
const wxString& aDestFileName ) const
{ {
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 rootFn = g_RootSheet->GetFileName();
wxFileName srcFn = aSrcFileName; wxFileName srcFn = aSrcFileName;
wxFileName destFn = aDestFileName; 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. // The source and destination sheet file names cannot be the same.
if( srcFn == destFn ) if( srcFn == destFn )
{
m_recursion_test_cache[pair] = true;
return true; return true;
}
/// @todo Store sheet file names with full path, either relative to project path /// @todo Store sheet file names with full path, either relative to project path
/// or absolute path. The current design always assumes subsheet files are /// 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 // 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. // sheet file name is the root sheet so no recursion is possible.
if( i >= size() || i == 0 ) if( i >= size() || i == 0 )
{
m_recursion_test_cache[pair] = false;
return false; return false;
}
// Walk back up to the root sheet to see if the source file name is already a parent in // 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. // the sheet path. If so, recursion will occur.
@ -308,11 +318,15 @@ bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName,
cmpFn.MakeAbsolute( rootFn.GetPath() ); cmpFn.MakeAbsolute( rootFn.GetPath() );
if( cmpFn == srcFn ) if( cmpFn == srcFn )
{
m_recursion_test_cache[pair] = true;
return true; return true;
}
} while( i != 0 ); } while( i != 0 );
// The source sheet file name is not a parent of the destination sheet file name. // The source sheet file name is not a parent of the destination sheet file name.
m_recursion_test_cache[pair] = false;
return false; return false;
} }
@ -642,7 +656,7 @@ bool SCH_SHEET_LIST::IsComplexHierarchy() const
bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy, bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
const wxString& aDestFileName ) const const wxString& aDestFileName )
{ {
wxFileName rootFn = g_RootSheet->GetFileName(); wxFileName rootFn = g_RootSheet->GetFileName();
wxFileName destFn = aDestFileName; wxFileName destFn = aDestFileName;

View File

@ -116,6 +116,8 @@ protected:
int m_pageNumber; /// Page numbers are maintained by the sheet load order. int m_pageNumber; /// Page numbers are maintained by the sheet load order.
std::map<std::pair<wxString, wxString>, bool> m_recursion_test_cache;
public: public:
SCH_SHEET_PATH(); SCH_SHEET_PATH();
@ -283,7 +285,7 @@ public:
* @param aDestFileName is the file name of the destination sheet for \a aSrcFileName. * @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. * @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; 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. * @return true if \a aFileName will cause recursion in the sheet path. Otherwise false.
*/ */
bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy, bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
const wxString& aDestFileName ) const; const wxString& aDestFileName );
/** /**
* Function FindSheetForScreen * Function FindSheetForScreen