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.

(cherry picked from commit e543ff0578)
This commit is contained in:
Jeff Young 2024-06-06 11:31:22 +01:00
parent 76a68b1f8d
commit 5ca3414707
17 changed files with 57 additions and 51 deletions

View File

@ -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<SCH_SHEET*>( item )->GetShownName( false );

View File

@ -513,7 +513,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 )
{

View File

@ -677,7 +677,7 @@ void DIALOG_SCH_FIELD_PROPERTIES::UpdateField( SCH_COMMIT* aCommit, SCH_FIELD* a
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<SCH_SYMBOL*> otherUnits;

View File

@ -792,7 +792,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<SCH_SYMBOL*> otherUnits;

View File

@ -150,7 +150,7 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_ITE
m_separator5->SetIsSeparator();
SCH_SHEET_LIST sheetList = m_frame->Schematic().GetSheets();
SCH_SHEET_LIST sheetList = m_frame->Schematic().GetUnorderedSheets();
sheetList.SortByPageNumbers( false );
for( const SCH_SHEET_PATH& sheet : sheetList )

View File

@ -1075,7 +1075,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;
}

View File

@ -171,7 +171,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 */ );
@ -206,7 +207,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() )
@ -243,6 +244,8 @@ void SCH_EDIT_FRAME::RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelect
if( m_netNavigator->IsEmpty() && m_highlightedConn.IsEmpty() )
return;
bool singleSheetSchematic = m_schematic->GetUnorderedSheets().size() == 1;
if( !m_netNavigator->IsEmpty() && m_highlightedConn.IsEmpty() )
{
m_netNavigator->DeleteAllItems();
@ -259,7 +262,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
{
@ -273,14 +276,14 @@ void SCH_EDIT_FRAME::RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelect
m_netNavigator->DeleteAllItems();
wxTreeItemId rootId = m_netNavigator->AddRoot( UnescapeString( m_highlightedConn ), 0 );
MakeNetNavigatorNode( m_highlightedConn, rootId, itemData );
MakeNetNavigatorNode( m_highlightedConn, rootId, itemData, singleSheetSchematic );
}
}
else
{
wxTreeItemId rootId = m_netNavigator->AddRoot( UnescapeString( m_highlightedConn ), 0 );
MakeNetNavigatorNode( m_highlightedConn, rootId, aSelection );
MakeNetNavigatorNode( m_highlightedConn, rootId, aSelection, singleSheetSchematic );
}
}

View File

@ -774,7 +774,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 );
}
@ -894,7 +894,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;
}
@ -942,9 +942,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?" );
@ -965,7 +963,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 )
@ -2037,7 +2035,7 @@ const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
bool SCH_EDIT_FRAME::IsContentModified() const
{
return Schematic().GetSheets().IsModified();
return Schematic().GetUnorderedSheets().IsModified();
}
@ -2052,9 +2050,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 )
{

View File

@ -866,7 +866,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 );

View File

@ -740,11 +740,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++ )
{

View File

@ -108,7 +108,7 @@ wxString SCH_MARKER::Serialize() const
}
SCH_MARKER* SCH_MARKER::Deserialize( SCHEMATIC* schematic, const wxString& data )
SCH_MARKER* SCH_MARKER::Deserialize( const SCH_SHEET_LIST& aSheetList, const wxString& data )
{
wxArrayString props = wxSplit( data, '|' );
VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
@ -131,13 +131,11 @@ SCH_MARKER* SCH_MARKER::Deserialize( SCHEMATIC* schematic, const wxString& data
{
isLegacyMarker = false;
SCH_SHEET_LIST sheetPaths = schematic->GetSheets();
if( !props[5].IsEmpty() )
{
KIID_PATH sheetSpecificKiidPath( props[5] );
std::optional<SCH_SHEET_PATH> sheetSpecificPath =
sheetPaths.GetSheetPathByKIIDPath( sheetSpecificKiidPath, true );
aSheetList.GetSheetPathByKIIDPath( sheetSpecificKiidPath, true );
if( sheetSpecificPath.has_value() )
ercItem->SetSheetSpecificPath( sheetSpecificPath.value() );
}
@ -146,7 +144,7 @@ SCH_MARKER* SCH_MARKER::Deserialize( SCHEMATIC* schematic, const wxString& data
{
KIID_PATH mainItemKiidPath( props[6] );
std::optional<SCH_SHEET_PATH> mainItemPath =
sheetPaths.GetSheetPathByKIIDPath( mainItemKiidPath, true );
aSheetList.GetSheetPathByKIIDPath( mainItemKiidPath, true );
if( mainItemPath.has_value() )
{
if( props[7].IsEmpty() )
@ -157,7 +155,7 @@ SCH_MARKER* SCH_MARKER::Deserialize( SCHEMATIC* schematic, const wxString& data
{
KIID_PATH auxItemKiidPath( props[7] );
std::optional<SCH_SHEET_PATH> auxItemPath =
sheetPaths.GetSheetPathByKIIDPath( auxItemKiidPath, true );
aSheetList.GetSheetPathByKIIDPath( auxItemKiidPath, true );
if( auxItemPath.has_value() )
ercItem->SetItemsSheetPaths( mainItemPath.value(), auxItemPath.value() );

View File

@ -54,7 +54,7 @@ public:
void SwapData( SCH_ITEM* aItem ) override;
wxString Serialize() const;
static SCH_MARKER* Deserialize( SCHEMATIC* schematic, const wxString& data );
static SCH_MARKER* Deserialize( const SCH_SHEET_LIST& aSheetList, const wxString& data );
void ViewGetLayers( int aLayers[], int& aCount ) const override;

View File

@ -283,8 +283,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" ) ) )

View File

@ -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<SCH_SYMBOL*> otherUnits;
@ -314,7 +314,7 @@ std::vector<SCH_MARKER*> SCHEMATIC::ResolveERCExclusions()
for( auto it = settings.m_ErcExclusions.begin(); it != settings.m_ErcExclusions.end(); )
{
SCH_MARKER* testMarker = SCH_MARKER::Deserialize( this, *it );
SCH_MARKER* testMarker = SCH_MARKER::Deserialize( sheetList, *it );
if( testMarker->IsLegacyMarker() )
{
@ -361,7 +361,7 @@ std::vector<SCH_MARKER*> SCHEMATIC::ResolveERCExclusions()
for( const wxString& serialized : settings.m_ErcExclusions )
{
SCH_MARKER* marker = SCH_MARKER::Deserialize( this, serialized );
SCH_MARKER* marker = SCH_MARKER::Deserialize( sheetList, serialized );
if( marker )
{
@ -378,7 +378,7 @@ std::vector<SCH_MARKER*> SCHEMATIC::ResolveERCExclusions()
std::shared_ptr<BUS_ALIAS> 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<BUS_ALIAS>& alias : sheet.LastScreen()->GetBusAliases() )
{
@ -412,11 +412,10 @@ std::set<wxString> 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 )
{
@ -449,7 +448,7 @@ std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetNamesMap() const
{
std::map<int, wxString> namesMap;
for( const SCH_SHEET_PATH& sheet : GetSheets() )
for( const SCH_SHEET_PATH& sheet : GetUnorderedSheets() )
{
if( sheet.size() == 1 )
namesMap[sheet.GetVirtualPageNumber()] = _( "<root sheet>" );
@ -465,7 +464,7 @@ std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetPagesMap() const
{
std::map<int, wxString> pagesMap;
for( const SCH_SHEET_PATH& sheet : GetSheets() )
for( const SCH_SHEET_PATH& sheet : GetUnorderedSheets() )
pagesMap[sheet.GetVirtualPageNumber()] = sheet.GetPageNumber();
return pagesMap;
@ -509,12 +508,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++ )
{
@ -565,12 +563,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 )
{
@ -739,10 +736,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<EDA_ITEM*> allItems;
for( auto item : screen->Items() )
@ -836,7 +833,7 @@ void SCHEMATIC::RecordERCExclusions()
void SCHEMATIC::ResolveERCExclusionsPostUpdate()
{
SCH_SHEET_LIST sheetList = GetSheets();
SCH_SHEET_LIST sheetList = GetUnorderedSheets();
for( SCH_MARKER* marker : ResolveERCExclusions() )
{

View File

@ -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;

View File

@ -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();
}