From e543ff05781d1648f6dfa34d9ed08cd9566ca2e7 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 6 Jun 2024 11:31:22 +0100 Subject: [PATCH] Performance for large hierarchies: lookups Don't bother to sort sheet lists when we're just looking up a UUID, sheet count, other symbol units, etc. --- eeschema/cross-probing.cpp | 2 +- eeschema/dialogs/dialog_erc.cpp | 2 +- eeschema/dialogs/dialog_field_properties.cpp | 2 +- eeschema/dialogs/dialog_symbol_properties.cpp | 2 +- eeschema/dialogs/dialog_table_properties.cpp | 3 +- eeschema/dialogs/dialog_text_properties.cpp | 1 - eeschema/files-io.cpp | 2 +- eeschema/net_navigator.cpp | 16 +++++---- eeschema/sch_edit_frame.cpp | 15 ++++----- eeschema/sch_edit_frame.h | 3 +- eeschema/sch_field.cpp | 3 +- eeschema/sch_sheet.cpp | 3 +- eeschema/schematic.cpp | 33 +++++++++---------- eeschema/schematic.h | 12 +++++++ eeschema/tools/sch_navigate_tool.cpp | 2 +- 15 files changed, 53 insertions(+), 48 deletions(-) diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index b2d51d51a6..0116437321 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -907,7 +907,7 @@ void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) KIID uuid( payload ); SCH_SHEET_PATH path; - if( SCH_ITEM* item = m_schematic->GetSheets().GetItem( uuid, &path ) ) + if( SCH_ITEM* item = m_schematic->GetItem( uuid, &path ) ) { if( item->Type() == SCH_SHEET_T ) payload = static_cast( item )->GetShownName( false ); diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 0af14f8c54..880598fe7d 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -531,7 +531,7 @@ void DIALOG_ERC::OnERCItemSelected( wxDataViewEvent& aEvent ) { const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() ); SCH_SHEET_PATH sheet; - SCH_ITEM* item = m_parent->Schematic().GetSheets().GetItem( itemID, &sheet ); + SCH_ITEM* item = m_parent->Schematic().GetItem( itemID, &sheet ); if( m_centerMarkerOnIdle ) { diff --git a/eeschema/dialogs/dialog_field_properties.cpp b/eeschema/dialogs/dialog_field_properties.cpp index 771e32f801..b89de9710a 100644 --- a/eeschema/dialogs/dialog_field_properties.cpp +++ b/eeschema/dialogs/dialog_field_properties.cpp @@ -672,7 +672,7 @@ void DIALOG_FIELD_PROPERTIES::UpdateField( SCH_COMMIT* aCommit, SCH_FIELD* aFiel int unit = symbol->GetUnit(); LIB_ID libId = symbol->GetLibId(); - for( SCH_SHEET_PATH& sheet : editFrame->Schematic().GetSheets() ) + for( SCH_SHEET_PATH& sheet : editFrame->Schematic().GetUnorderedSheets() ) { SCH_SCREEN* screen = sheet.LastScreen(); std::vector otherUnits; diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index c68c714b52..83aef4aa3b 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -785,7 +785,7 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow() int unit = m_symbol->GetUnit(); LIB_ID libId = m_symbol->GetLibId(); - for( SCH_SHEET_PATH& sheet : GetParent()->Schematic().GetSheets() ) + for( SCH_SHEET_PATH& sheet : GetParent()->Schematic().GetUnorderedSheets() ) { SCH_SCREEN* screen = sheet.LastScreen(); std::vector otherUnits; diff --git a/eeschema/dialogs/dialog_table_properties.cpp b/eeschema/dialogs/dialog_table_properties.cpp index c7fac4c293..421260c0c6 100644 --- a/eeschema/dialogs/dialog_table_properties.cpp +++ b/eeschema/dialogs/dialog_table_properties.cpp @@ -239,11 +239,10 @@ void DIALOG_TABLE_PROPERTIES::getContextualTextVars( const wxString& aCrossRef, { if( !aCrossRef.IsEmpty() ) { - SCH_SHEET_LIST sheets = m_frame->Schematic().GetSheets(); SCH_REFERENCE_LIST refs; SCH_SYMBOL* refSymbol = nullptr; - sheets.GetSymbols( refs ); + m_frame->Schematic().GetUnorderedSheets().GetSymbols( refs ); for( int jj = 0; jj < (int) refs.GetCount(); jj++ ) { diff --git a/eeschema/dialogs/dialog_text_properties.cpp b/eeschema/dialogs/dialog_text_properties.cpp index aa6ee64bf0..685bc3a744 100644 --- a/eeschema/dialogs/dialog_text_properties.cpp +++ b/eeschema/dialogs/dialog_text_properties.cpp @@ -165,7 +165,6 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( SCH_BASE_FRAME* aParent, SCH_ITE if( SCH_EDIT_FRAME* schematicEditor = dynamic_cast( m_frame ) ) { SCH_SHEET_LIST sheetList = schematicEditor->Schematic().GetSheets(); - sheetList.SortByPageNumbers( false ); for( const SCH_SHEET_PATH& sheet : sheetList ) { diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index dde09c106c..0ee8d82573 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -1089,7 +1089,7 @@ bool SCH_EDIT_FRAME::SaveProject( bool aSaveAs ) // File doesn't exist yet; true if we just imported something updateFileHistory = true; } - else if( !Schematic().GetSheets().IsModified() ) + else if( !IsContentModified() ) { return true; } diff --git a/eeschema/net_navigator.cpp b/eeschema/net_navigator.cpp index 2632a8a0a2..89cbe794b9 100644 --- a/eeschema/net_navigator.cpp +++ b/eeschema/net_navigator.cpp @@ -194,7 +194,8 @@ static wxString GetNetNavigatorItemText( const SCH_ITEM* aItem, void SCH_EDIT_FRAME::MakeNetNavigatorNode( const wxString& aNetName, wxTreeItemId aParentId, - const NET_NAVIGATOR_ITEM_DATA* aSelection ) + const NET_NAVIGATOR_ITEM_DATA* aSelection, + bool aSingleSheetSchematic ) { wxCHECK( !aNetName.IsEmpty(), /* void */ ); wxCHECK( m_schematic, /* void */ ); @@ -229,7 +230,7 @@ void SCH_EDIT_FRAME::MakeNetNavigatorNode( const wxString& aNetName, wxTreeItemI m_netNavigator->SelectItem( sheetId ); // If there is only one sheet in the schematic, always expand the sheet tree. - if( Schematic().GetSheets().size() == 1 ) + if( aSingleSheetSchematic ) expandId = sheetId; for( const SCH_ITEM* item : subGraph->GetItems() ) @@ -266,7 +267,8 @@ void SCH_EDIT_FRAME::RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelect if( !m_netNavigator->IsShown() ) return; - size_t nodeCnt = 0; + bool singleSheetSchematic = m_schematic->GetUnorderedSheets().size() == 1; + size_t nodeCnt = 0; m_netNavigator->Freeze(); @@ -290,7 +292,7 @@ void SCH_EDIT_FRAME::RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelect nodeCnt++; wxTreeItemId netId = m_netNavigator->AppendItem( rootId, UnescapeString( net.first.Name ) ); - MakeNetNavigatorNode( net.first.Name, netId, aSelection ); + MakeNetNavigatorNode( net.first.Name, netId, aSelection, singleSheetSchematic ); } m_netNavigator->Expand( rootId ); @@ -307,7 +309,7 @@ void SCH_EDIT_FRAME::RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelect wxTreeItemId rootId = m_netNavigator->AddRoot( UnescapeString( m_highlightedConn ), 0 ); - MakeNetNavigatorNode( m_highlightedConn, rootId, aSelection ); + MakeNetNavigatorNode( m_highlightedConn, rootId, aSelection, singleSheetSchematic ); } else { @@ -323,7 +325,7 @@ void SCH_EDIT_FRAME::RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelect wxTreeItemId rootId = m_netNavigator->AddRoot( UnescapeString( m_highlightedConn ), 0 ); - MakeNetNavigatorNode( m_highlightedConn, rootId, itemData ); + MakeNetNavigatorNode( m_highlightedConn, rootId, itemData, singleSheetSchematic ); } } else @@ -332,7 +334,7 @@ void SCH_EDIT_FRAME::RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelect wxTreeItemId rootId = m_netNavigator->AddRoot( UnescapeString( m_highlightedConn ), 0 ); - MakeNetNavigatorNode( m_highlightedConn, rootId, aSelection ); + MakeNetNavigatorNode( m_highlightedConn, rootId, aSelection, singleSheetSchematic ); } timer.Stop(); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index cada5b0288..53dc68526f 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -822,7 +822,7 @@ void SCH_EDIT_FRAME::AddCopyForRepeatItem( const SCH_ITEM* aItem ) EDA_ITEM* SCH_EDIT_FRAME::GetItem( const KIID& aId ) const { - return Schematic().GetSheets().GetItem( aId ); + return Schematic().GetItem( aId ); } @@ -942,7 +942,7 @@ bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) // Shutdown blocks must be determined and vetoed as early as possible if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION - && Schematic().GetSheets().IsModified() ) + && IsContentModified() ) { return false; } @@ -990,9 +990,7 @@ bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) if( !Schematic().IsValid() ) return false; - SCH_SHEET_LIST sheetlist = Schematic().GetSheets(); - - if( sheetlist.IsModified() ) + if( IsContentModified() ) { wxFileName fileName = Schematic().RootScreen()->GetFileName(); wxString msg = _( "Save changes to '%s' before closing?" ); @@ -1013,7 +1011,7 @@ bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) void SCH_EDIT_FRAME::doCloseWindow() { - SCH_SHEET_LIST sheetlist = Schematic().GetSheets(); + SCH_SHEET_LIST sheetlist = Schematic().GetUnorderedSheets(); // Shutdown all running tools if( m_toolManager ) @@ -2201,7 +2199,7 @@ const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const bool SCH_EDIT_FRAME::IsContentModified() const { - return Schematic().GetSheets().IsModified(); + return Schematic().GetUnorderedSheets().IsModified(); } @@ -2216,9 +2214,8 @@ void SCH_EDIT_FRAME::FocusOnItem( SCH_ITEM* aItem ) { static KIID lastBrightenedItemID( niluuid ); - SCH_SHEET_LIST sheetList = Schematic().GetSheets(); SCH_SHEET_PATH dummy; - SCH_ITEM* lastItem = sheetList.GetItem( lastBrightenedItemID, &dummy ); + SCH_ITEM* lastItem = Schematic().GetItem( lastBrightenedItemID, &dummy ); if( lastItem && lastItem != aItem ) { diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 5d6874a420..e803c576a6 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -871,7 +871,8 @@ public: void RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelection = nullptr ); void MakeNetNavigatorNode( const wxString& aNetName, wxTreeItemId aParentId, - const NET_NAVIGATOR_ITEM_DATA* aSelection = nullptr ); + const NET_NAVIGATOR_ITEM_DATA* aSelection, + bool aSingleSheetSchematic ); void SelectNetNavigatorItem( const NET_NAVIGATOR_ITEM_DATA* aSelection = nullptr ); diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 678d8aa04f..5dc82f7e82 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -855,11 +855,10 @@ void SCH_FIELD::OnScintillaCharAdded( SCINTILLA_TRICKS* aScintillaTricks, } else { - SCH_SHEET_LIST sheets = schematic->GetSheets(); SCH_REFERENCE_LIST refs; SCH_SYMBOL* refSymbol = nullptr; - sheets.GetSymbols( refs ); + schematic->GetUnorderedSheets().GetSymbols( refs ); for( size_t jj = 0; jj < refs.GetCount(); jj++ ) { diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 53cbe84688..6993e31375 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -297,8 +297,7 @@ bool SCH_SHEET::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, in } else if( token->IsSameAs( wxT( "##" ) ) ) { - SCH_SHEET_LIST sheetList = schematic->GetSheets(); - *token = wxString::Format( wxT( "%d" ), (int) sheetList.size() ); + *token = wxString::Format( wxT( "%d" ), (int) schematic->GetUnorderedSheets().size() ); return true; } else if( token->IsSameAs( wxT( "SHEETPATH" ) ) ) diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index 1813fe7bb4..3e461478c4 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -72,7 +72,7 @@ SCHEMATIC::SCHEMATIC( PROJECT* aPrj ) : int unit = symbol->GetUnit(); LIB_ID libId = symbol->GetLibId(); - for( SCH_SHEET_PATH& sheet : GetSheets() ) + for( SCH_SHEET_PATH& sheet : GetUnorderedSheets() ) { std::vector otherUnits; @@ -314,7 +314,7 @@ std::vector SCHEMATIC::ResolveERCExclusions() for( auto it = settings.m_ErcExclusions.begin(); it != settings.m_ErcExclusions.end(); ) { - SCH_MARKER* testMarker = SCH_MARKER::DeserializeFromString( this, *it ); + SCH_MARKER* testMarker = SCH_MARKER::DeserializeFromString( sheetList, *it ); if( !testMarker ) { @@ -367,7 +367,7 @@ std::vector SCHEMATIC::ResolveERCExclusions() for( const wxString& serialized : settings.m_ErcExclusions ) { - SCH_MARKER* marker = SCH_MARKER::DeserializeFromString( this, serialized ); + SCH_MARKER* marker = SCH_MARKER::DeserializeFromString( sheetList, serialized ); if( marker ) { @@ -384,7 +384,7 @@ std::vector SCHEMATIC::ResolveERCExclusions() std::shared_ptr SCHEMATIC::GetBusAlias( const wxString& aLabel ) const { - for( const SCH_SHEET_PATH& sheet : GetSheets() ) + for( const SCH_SHEET_PATH& sheet : GetUnorderedSheets() ) { for( const std::shared_ptr& alias : sheet.LastScreen()->GetBusAliases() ) { @@ -418,11 +418,10 @@ std::set SCHEMATIC::GetNetClassAssignmentCandidates() bool SCHEMATIC::ResolveCrossReference( wxString* token, int aDepth ) const { - SCH_SHEET_LIST sheetList = GetSheets(); wxString remainder; wxString ref = token->BeforeFirst( ':', &remainder ); SCH_SHEET_PATH sheetPath; - SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &sheetPath ); + SCH_ITEM* refItem = GetItem( KIID( ref ), &sheetPath ); if( refItem && refItem->Type() == SCH_SYMBOL_T ) { @@ -455,7 +454,7 @@ std::map SCHEMATIC::GetVirtualPageToSheetNamesMap() const { std::map namesMap; - for( const SCH_SHEET_PATH& sheet : GetSheets() ) + for( const SCH_SHEET_PATH& sheet : GetUnorderedSheets() ) { if( sheet.size() == 1 ) namesMap[sheet.GetVirtualPageNumber()] = _( "" ); @@ -471,7 +470,7 @@ std::map SCHEMATIC::GetVirtualPageToSheetPagesMap() const { std::map pagesMap; - for( const SCH_SHEET_PATH& sheet : GetSheets() ) + for( const SCH_SHEET_PATH& sheet : GetUnorderedSheets() ) pagesMap[sheet.GetVirtualPageNumber()] = sheet.GetPageNumber(); return pagesMap; @@ -515,12 +514,11 @@ wxString SCHEMATIC::ConvertRefsToKIIDs( const wxString& aSource ) const if( isCrossRef ) { - SCH_SHEET_LIST sheetList = GetSheets(); wxString remainder; wxString ref = token.BeforeFirst( ':', &remainder ); SCH_REFERENCE_LIST references; - sheetList.GetSymbols( references ); + GetUnorderedSheets().GetSymbols( references ); for( size_t jj = 0; jj < references.GetCount(); jj++ ) { @@ -571,12 +569,11 @@ wxString SCHEMATIC::ConvertKIIDsToRefs( const wxString& aSource ) const if( isCrossRef ) { - SCH_SHEET_LIST sheetList = GetSheets(); - wxString remainder; - wxString ref = token.BeforeFirst( ':', &remainder ); + wxString remainder; + wxString ref = token.BeforeFirst( ':', &remainder ); SCH_SHEET_PATH refSheetPath; - SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &refSheetPath ); + SCH_ITEM* refItem = GetItem( KIID( ref ), &refSheetPath ); if( refItem && refItem->Type() == SCH_SYMBOL_T ) { @@ -728,10 +725,10 @@ wxString SCHEMATIC::GetOperatingPoint( const wxString& aNetName, int aPrecision, void SCHEMATIC::FixupJunctions() { - for( const SCH_SHEET_PATH& sheet : GetSheets() ) - { - SCH_SCREEN* screen = sheet.LastScreen(); + SCH_SCREENS screens( Root() ); + for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() ) + { std::deque allItems; for( auto item : screen->Items() ) @@ -830,7 +827,7 @@ void SCHEMATIC::RecordERCExclusions() void SCHEMATIC::ResolveERCExclusionsPostUpdate() { - SCH_SHEET_LIST sheetList = GetSheets(); + SCH_SHEET_LIST sheetList = GetUnorderedSheets(); for( SCH_MARKER* marker : ResolveERCExclusions() ) { diff --git a/eeschema/schematic.h b/eeschema/schematic.h index 81186a744d..1ebc3cfe2f 100644 --- a/eeschema/schematic.h +++ b/eeschema/schematic.h @@ -102,6 +102,18 @@ public: return SCH_SHEET_LIST( m_rootSheet ); } + SCH_SHEET_LIST GetUnorderedSheets() const + { + SCH_SHEET_LIST sheets; + sheets.BuildSheetList( m_rootSheet, false ); + return sheets; + } + + SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr ) const + { + return GetUnorderedSheets().GetItem( aID, aPathOut ); + } + SCH_SHEET& Root() const { return *m_rootSheet; diff --git a/eeschema/tools/sch_navigate_tool.cpp b/eeschema/tools/sch_navigate_tool.cpp index 5db86f1a22..f027eb2e0d 100644 --- a/eeschema/tools/sch_navigate_tool.cpp +++ b/eeschema/tools/sch_navigate_tool.cpp @@ -201,7 +201,7 @@ bool SCH_NAVIGATE_TOOL::CanGoPrevious() bool SCH_NAVIGATE_TOOL::CanGoNext() { return m_frame->GetCurrentSheet().GetVirtualPageNumber() - < (int) m_frame->Schematic().GetSheets().size(); + < (int) m_frame->Schematic().GetUnorderedSheets().size(); }