Prefer const& to passing by value.

This commit is contained in:
Jeff Young 2025-06-06 13:31:06 +01:00
parent cda127a9a3
commit 1968d67bf3
14 changed files with 31 additions and 45 deletions

View File

@ -45,7 +45,7 @@ public:
m_hash( 0 ) m_hash( 0 )
{} {}
ERC_SCH_PIN_CONTEXT( SCH_PIN* pin, SCH_SHEET_PATH sheet ) : ERC_SCH_PIN_CONTEXT( SCH_PIN* pin, const SCH_SHEET_PATH& sheet ) :
m_pin( pin ), m_pin( pin ),
m_sheet( sheet ) m_sheet( sheet )
{ {

View File

@ -141,7 +141,7 @@ void NETLIST_EXPORTER_ALLEGRO::extractComponentsInfo()
m_schematic->SetCurrentSheet( sheet ); m_schematic->SetCurrentSheet( sheet );
auto cmp = auto cmp =
[sheet]( SCH_SYMBOL* a, SCH_SYMBOL* b ) [&sheet]( SCH_SYMBOL* a, SCH_SYMBOL* b )
{ {
return ( StrNumCmp( a->GetRef( &sheet, false ), return ( StrNumCmp( a->GetRef( &sheet, false ),
b->GetRef( &sheet, false ), true ) < 0 ); b->GetRef( &sheet, false ), true ) < 0 );

View File

@ -155,7 +155,7 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f )
// Intra-net ordering: Ref des, then pin name // Intra-net ordering: Ref des, then pin name
std::sort( sorted_items.begin(), sorted_items.end(), std::sort( sorted_items.begin(), sorted_items.end(),
[]( std::pair<SCH_PIN*, SCH_SHEET_PATH> a, std::pair<SCH_PIN*, SCH_SHEET_PATH> b ) []( const std::pair<SCH_PIN*, SCH_SHEET_PATH>& a, const std::pair<SCH_PIN*, SCH_SHEET_PATH>& b )
{ {
wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second ); wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second ); wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
@ -170,7 +170,7 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f )
// pins across units. If the user connects the pins on each unit, they will // pins across units. If the user connects the pins on each unit, they will
// appear on separate subgraphs. Remove those here: // appear on separate subgraphs. Remove those here:
sorted_items.erase( std::unique( sorted_items.begin(), sorted_items.end(), sorted_items.erase( std::unique( sorted_items.begin(), sorted_items.end(),
[]( std::pair<SCH_PIN*, SCH_SHEET_PATH> a, std::pair<SCH_PIN*, SCH_SHEET_PATH> b ) []( const std::pair<SCH_PIN*, SCH_SHEET_PATH>& a, const std::pair<SCH_PIN*, SCH_SHEET_PATH>& b )
{ {
wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second ); wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second ); wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );

View File

@ -126,7 +126,7 @@ bool NETLIST_EXPORTER_PADS::writeListOfNets( FILE* f )
// Netlist ordering: Net name, then ref des, then pin name // Netlist ordering: Net name, then ref des, then pin name
std::sort( sorted_items.begin(), sorted_items.end(), std::sort( sorted_items.begin(), sorted_items.end(),
[]( std::pair<SCH_PIN*, SCH_SHEET_PATH> a, std::pair<SCH_PIN*, SCH_SHEET_PATH> b ) []( const std::pair<SCH_PIN*, SCH_SHEET_PATH>& a, const std::pair<SCH_PIN*, SCH_SHEET_PATH>& b )
{ {
wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second ); wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second ); wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
@ -141,7 +141,7 @@ bool NETLIST_EXPORTER_PADS::writeListOfNets( FILE* f )
// pins across units. If the user connects the pins on each unit, they will // pins across units. If the user connects the pins on each unit, they will
// appear on separate subgraphs. Remove those here: // appear on separate subgraphs. Remove those here:
sorted_items.erase( std::unique( sorted_items.begin(), sorted_items.end(), sorted_items.erase( std::unique( sorted_items.begin(), sorted_items.end(),
[]( std::pair<SCH_PIN*, SCH_SHEET_PATH> a, std::pair<SCH_PIN*, SCH_SHEET_PATH> b ) []( const std::pair<SCH_PIN*, SCH_SHEET_PATH>& a, const std::pair<SCH_PIN*, SCH_SHEET_PATH>& b )
{ {
wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second ); wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second ); wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
@ -164,8 +164,7 @@ bool NETLIST_EXPORTER_PADS::writeListOfNets( FILE* f )
if( refText[0] == wxChar( '#' ) ) if( refText[0] == wxChar( '#' ) )
continue; continue;
netConns.push_back( netConns.push_back( wxString::Format( "%s.%.4s", refText, pinText ) );
wxString::Format( "%s.%.4s", refText, pinText ) );
} }
// format it such that there are 6 net connections per line // format it such that there are 6 net connections per line
@ -174,17 +173,15 @@ bool NETLIST_EXPORTER_PADS::writeListOfNets( FILE* f )
{ {
ret |= fprintf( f, "*SIGNAL* %s\n", TO_UTF8(netName) ); ret |= fprintf( f, "*SIGNAL* %s\n", TO_UTF8(netName) );
int cnt = 0; int cnt = 0;
for( wxString& netConn : netConns ) for( wxString& netConn : netConns )
{ {
ret |= fputs( TO_UTF8( netConn ), f ); ret |= fputs( TO_UTF8( netConn ), f );
if( cnt != 0 && cnt % 6 == 0 ) if( cnt != 0 && cnt % 6 == 0 )
{
ret |= fputc( '\n', f ); ret |= fputc( '\n', f );
}
else else
{
ret |= fputc( ' ', f ); ret |= fputc( ' ', f );
}
cnt++; cnt++;
} }

View File

@ -267,7 +267,7 @@ XNODE* NETLIST_EXPORTER_XML::makeSymbols( unsigned aCtl )
m_schematic->SetCurrentSheet( sheet ); m_schematic->SetCurrentSheet( sheet );
auto cmp = auto cmp =
[sheet]( SCH_SYMBOL* a, SCH_SYMBOL* b ) [&sheet]( SCH_SYMBOL* a, SCH_SYMBOL* b )
{ {
return ( StrNumCmp( a->GetRef( &sheet, false ), return ( StrNumCmp( a->GetRef( &sheet, false ),
b->GetRef( &sheet, false ), true ) < 0 ); b->GetRef( &sheet, false ), true ) < 0 );

View File

@ -119,7 +119,7 @@ void SCH_CONNECTION::SetDriver( SCH_ITEM* aItem )
} }
void SCH_CONNECTION::SetSheet( SCH_SHEET_PATH aSheet ) void SCH_CONNECTION::SetSheet( const SCH_SHEET_PATH& aSheet )
{ {
m_sheet = aSheet; m_sheet = aSheet;
m_local_sheet = aSheet; m_local_sheet = aSheet;

View File

@ -108,7 +108,7 @@ public:
void SetDriver( SCH_ITEM* aItem ); void SetDriver( SCH_ITEM* aItem );
SCH_SHEET_PATH Sheet() const { return m_sheet; } SCH_SHEET_PATH Sheet() const { return m_sheet; }
void SetSheet( SCH_SHEET_PATH aSheet ); void SetSheet( const SCH_SHEET_PATH& aSheet );
SCH_SHEET_PATH LocalSheet() const { return m_local_sheet; } SCH_SHEET_PATH LocalSheet() const { return m_local_sheet; }

View File

@ -945,11 +945,11 @@ bool SCH_SHEET_LIST::PageNumberExists( const wxString& aPageNumber ) const
void SCH_SHEET_LIST::TrimToPageNumbers( const std::vector<wxString>& aPageInclusions ) void SCH_SHEET_LIST::TrimToPageNumbers( const std::vector<wxString>& aPageInclusions )
{ {
auto it = std::remove_if( begin(), end(), auto it = std::remove_if( begin(), end(),
[&]( SCH_SHEET_PATH sheet ) [&]( const SCH_SHEET_PATH& sheet )
{ {
return std::find( aPageInclusions.begin(), aPageInclusions.end(), return std::find( aPageInclusions.begin(),
sheet.GetPageNumber() ) aPageInclusions.end(),
== aPageInclusions.end(); sheet.GetPageNumber() ) == aPageInclusions.end();
} ); } );
erase( it, end() ); erase( it, end() );
@ -1319,7 +1319,7 @@ void SCH_SHEET_LIST::UpdateSheetInstanceData( const std::vector<SCH_SHEET_INSTAN
wxCHECK2( sheet && path.Last(), continue ); wxCHECK2( sheet && path.Last(), continue );
auto it = std::find_if( aSheetInstances.begin(), aSheetInstances.end(), auto it = std::find_if( aSheetInstances.begin(), aSheetInstances.end(),
[ path ]( const SCH_SHEET_INSTANCE& r ) -> bool [&path]( const SCH_SHEET_INSTANCE& r ) -> bool
{ {
return path.Path() == r.m_Path; return path.Path() == r.m_Path;
} ); } );

View File

@ -3305,8 +3305,7 @@ int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list<SCH_SHEET_PATH> sheetPaths )
}, },
[&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath ) [&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath )
{ {
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, &aPath );
SCH_ACTIONS::changeSheet, &aPath );
SCH_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>(); SCH_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
selectionTool->UnbrightenItem( aItem ); selectionTool->UnbrightenItem( aItem );
selectionTool->AddItemToSel( aItem, true ); selectionTool->AddItemToSel( aItem, true );
@ -3314,7 +3313,7 @@ int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list<SCH_SHEET_PATH> sheetPaths )
}, },
[&]( SCH_SHEET* aItem, SCH_SHEET_PATH aPath, [&]( SCH_SHEET* aItem, SCH_SHEET_PATH aPath,
SHEET_SYNCHRONIZATION_AGENT::SHEET_SYNCHRONIZATION_PLACEMENT aOp, SHEET_SYNCHRONIZATION_AGENT::SHEET_SYNCHRONIZATION_PLACEMENT aOp,
std::set<EDA_ITEM*> aTemplates ) std::set<EDA_ITEM*> aTemplates )
{ {
switch( aOp ) switch( aOp )
{ {
@ -3323,10 +3322,8 @@ int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list<SCH_SHEET_PATH> sheetPaths )
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem ); SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
m_dialogSyncSheetPin->Hide(); m_dialogSyncSheetPin->Hide();
m_dialogSyncSheetPin->PreparePlacementTemplate( m_dialogSyncSheetPin->PreparePlacementTemplate(
sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::HIERLABEL, sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::HIERLABEL, aTemplates );
aTemplates ); m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, &aPath );
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>(
SCH_ACTIONS::changeSheet, &aPath );
m_toolMgr->RunAction( SCH_ACTIONS::placeHierLabel ); m_toolMgr->RunAction( SCH_ACTIONS::placeHierLabel );
break; break;
} }
@ -3335,12 +3332,9 @@ int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list<SCH_SHEET_PATH> sheetPaths )
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem ); SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
m_dialogSyncSheetPin->Hide(); m_dialogSyncSheetPin->Hide();
m_dialogSyncSheetPin->PreparePlacementTemplate( m_dialogSyncSheetPin->PreparePlacementTemplate(
sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::SHEET_PIN, sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::SHEET_PIN, aTemplates );
aTemplates ); m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, &aPath );
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( m_toolMgr->GetTool<SCH_SELECTION_TOOL>()->SyncSelection( {}, nullptr, { sheet } );
SCH_ACTIONS::changeSheet, &aPath );
m_toolMgr->GetTool<SCH_SELECTION_TOOL>()->SyncSelection( {}, nullptr,
{ sheet } );
m_toolMgr->RunAction( SCH_ACTIONS::placeSheetPin ); m_toolMgr->RunAction( SCH_ACTIONS::placeSheetPin );
break; break;
} }

View File

@ -154,8 +154,7 @@ int SCH_EDITOR_CONTROL::Revert( const TOOL_EVENT& aEvent )
SCH_SHEET_PATH rootSheetPath; SCH_SHEET_PATH rootSheetPath;
rootSheetPath.push_back( &root ); rootSheetPath.push_back( &root );
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, &rootSheetPath );
&rootSheetPath );
wxSafeYield(); wxSafeYield();
} }

View File

@ -281,10 +281,7 @@ int SCH_FIND_REPLACE_TOOL::FindNext( const TOOL_EVENT& aEvent )
if( item ) if( item )
{ {
if( m_frame->Schematic().CurrentSheet() != sheet ) if( m_frame->Schematic().CurrentSheet() != sheet )
{ m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, &sheet );
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet,
&sheet );
}
break; break;
} }

View File

@ -284,7 +284,7 @@ void SCH_NAVIGATE_TOOL::setTransitions()
} }
void SCH_NAVIGATE_TOOL::pushToHistory( SCH_SHEET_PATH aPath ) void SCH_NAVIGATE_TOOL::pushToHistory( const SCH_SHEET_PATH& aPath )
{ {
if( CanGoForward() ) if( CanGoForward() )
m_navHistory.erase( std::next( m_navIndex ), m_navHistory.end() ); m_navHistory.erase( std::next( m_navIndex ), m_navHistory.end() );
@ -296,7 +296,7 @@ void SCH_NAVIGATE_TOOL::pushToHistory( SCH_SHEET_PATH aPath )
} }
void SCH_NAVIGATE_TOOL::changeSheet( SCH_SHEET_PATH aPath ) void SCH_NAVIGATE_TOOL::changeSheet( const SCH_SHEET_PATH& aPath )
{ {
m_frame->GetToolManager()->RunAction( ACTIONS::cancelInteractive ); m_frame->GetToolManager()->RunAction( ACTIONS::cancelInteractive );
m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear ); m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );

View File

@ -80,9 +80,9 @@ private:
///< Set up handlers for various events. ///< Set up handlers for various events.
void setTransitions() override; void setTransitions() override;
///< Clear history after this nav index and pushes aPath to history ///< Clear history after this nav index and pushes aPath to history
void pushToHistory( SCH_SHEET_PATH aPath ); void pushToHistory( const SCH_SHEET_PATH& aPath );
///< Change current sheet to aPath and handle history, zooming, etc. ///< Change current sheet to aPath and handle history, zooming, etc.
void changeSheet( SCH_SHEET_PATH aPath ); void changeSheet( const SCH_SHEET_PATH& aPath );
private: private:
std::list<SCH_SHEET_PATH> m_navHistory; std::list<SCH_SHEET_PATH> m_navHistory;

View File

@ -321,8 +321,7 @@ void HIERARCHY_PANE::onSelectSheetPath( wxTreeEvent& aEvent )
return; return;
SetCursor( wxCURSOR_ARROWWAIT ); SetCursor( wxCURSOR_ARROWWAIT );
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, &itemData->m_SheetPath );
&itemData->m_SheetPath );
SetCursor( wxCURSOR_ARROW ); SetCursor( wxCURSOR_ARROW );
} }