From 1968d67bf3687cb3644a86f4132e761dfd786763 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 6 Jun 2025 13:31:06 +0100 Subject: [PATCH] Prefer const& to passing by value. --- eeschema/erc/erc_sch_pin_context.h | 2 +- .../netlist_exporter_allegro.cpp | 2 +- .../netlist_exporter_cadstar.cpp | 4 ++-- .../netlist_exporter_pads.cpp | 13 +++++------- .../netlist_exporter_xml.cpp | 2 +- eeschema/sch_connection.cpp | 2 +- eeschema/sch_connection.h | 2 +- eeschema/sch_sheet_path.cpp | 10 +++++----- eeschema/tools/sch_drawing_tools.cpp | 20 +++++++------------ eeschema/tools/sch_editor_control.cpp | 3 +-- eeschema/tools/sch_find_replace_tool.cpp | 5 +---- eeschema/tools/sch_navigate_tool.cpp | 4 ++-- eeschema/tools/sch_navigate_tool.h | 4 ++-- eeschema/widgets/hierarchy_pane.cpp | 3 +-- 14 files changed, 31 insertions(+), 45 deletions(-) diff --git a/eeschema/erc/erc_sch_pin_context.h b/eeschema/erc/erc_sch_pin_context.h index 669dce8546..6e631f7b14 100644 --- a/eeschema/erc/erc_sch_pin_context.h +++ b/eeschema/erc/erc_sch_pin_context.h @@ -45,7 +45,7 @@ public: 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_sheet( sheet ) { diff --git a/eeschema/netlist_exporters/netlist_exporter_allegro.cpp b/eeschema/netlist_exporters/netlist_exporter_allegro.cpp index c8cf447cf5..4f244b1957 100644 --- a/eeschema/netlist_exporters/netlist_exporter_allegro.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_allegro.cpp @@ -141,7 +141,7 @@ void NETLIST_EXPORTER_ALLEGRO::extractComponentsInfo() m_schematic->SetCurrentSheet( sheet ); auto cmp = - [sheet]( SCH_SYMBOL* a, SCH_SYMBOL* b ) + [&sheet]( SCH_SYMBOL* a, SCH_SYMBOL* b ) { return ( StrNumCmp( a->GetRef( &sheet, false ), b->GetRef( &sheet, false ), true ) < 0 ); diff --git a/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp b/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp index 934ab8e8bf..69a702d8f8 100644 --- a/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp @@ -155,7 +155,7 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f ) // Intra-net ordering: Ref des, then pin name std::sort( sorted_items.begin(), sorted_items.end(), - []( std::pair a, std::pair b ) + []( const std::pair& a, const std::pair& b ) { wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.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 // appear on separate subgraphs. Remove those here: sorted_items.erase( std::unique( sorted_items.begin(), sorted_items.end(), - []( std::pair a, std::pair b ) + []( const std::pair& a, const std::pair& b ) { wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second ); wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second ); diff --git a/eeschema/netlist_exporters/netlist_exporter_pads.cpp b/eeschema/netlist_exporters/netlist_exporter_pads.cpp index 19ee8492c4..83af99019f 100644 --- a/eeschema/netlist_exporters/netlist_exporter_pads.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_pads.cpp @@ -126,7 +126,7 @@ bool NETLIST_EXPORTER_PADS::writeListOfNets( FILE* f ) // Netlist ordering: Net name, then ref des, then pin name std::sort( sorted_items.begin(), sorted_items.end(), - []( std::pair a, std::pair b ) + []( const std::pair& a, const std::pair& b ) { wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.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 // appear on separate subgraphs. Remove those here: sorted_items.erase( std::unique( sorted_items.begin(), sorted_items.end(), - []( std::pair a, std::pair b ) + []( const std::pair& a, const std::pair& b ) { wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.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( '#' ) ) continue; - netConns.push_back( - wxString::Format( "%s.%.4s", refText, pinText ) ); + netConns.push_back( wxString::Format( "%s.%.4s", refText, pinText ) ); } // 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) ); int cnt = 0; + for( wxString& netConn : netConns ) { ret |= fputs( TO_UTF8( netConn ), f ); + if( cnt != 0 && cnt % 6 == 0 ) - { ret |= fputc( '\n', f ); - } else - { ret |= fputc( ' ', f ); - } cnt++; } diff --git a/eeschema/netlist_exporters/netlist_exporter_xml.cpp b/eeschema/netlist_exporters/netlist_exporter_xml.cpp index b59b5a54af..93316dfd04 100644 --- a/eeschema/netlist_exporters/netlist_exporter_xml.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_xml.cpp @@ -267,7 +267,7 @@ XNODE* NETLIST_EXPORTER_XML::makeSymbols( unsigned aCtl ) m_schematic->SetCurrentSheet( sheet ); auto cmp = - [sheet]( SCH_SYMBOL* a, SCH_SYMBOL* b ) + [&sheet]( SCH_SYMBOL* a, SCH_SYMBOL* b ) { return ( StrNumCmp( a->GetRef( &sheet, false ), b->GetRef( &sheet, false ), true ) < 0 ); diff --git a/eeschema/sch_connection.cpp b/eeschema/sch_connection.cpp index 77092b651d..14c7b3ce83 100644 --- a/eeschema/sch_connection.cpp +++ b/eeschema/sch_connection.cpp @@ -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_local_sheet = aSheet; diff --git a/eeschema/sch_connection.h b/eeschema/sch_connection.h index d301d4d030..7deb27dd3b 100644 --- a/eeschema/sch_connection.h +++ b/eeschema/sch_connection.h @@ -108,7 +108,7 @@ public: void SetDriver( SCH_ITEM* aItem ); 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; } diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 143c33ab1c..74af572d85 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -945,11 +945,11 @@ bool SCH_SHEET_LIST::PageNumberExists( const wxString& aPageNumber ) const void SCH_SHEET_LIST::TrimToPageNumbers( const std::vector& aPageInclusions ) { auto it = std::remove_if( begin(), end(), - [&]( SCH_SHEET_PATH sheet ) + [&]( const SCH_SHEET_PATH& sheet ) { - return std::find( aPageInclusions.begin(), aPageInclusions.end(), - sheet.GetPageNumber() ) - == aPageInclusions.end(); + return std::find( aPageInclusions.begin(), + aPageInclusions.end(), + sheet.GetPageNumber() ) == aPageInclusions.end(); } ); erase( it, end() ); @@ -1319,7 +1319,7 @@ void SCH_SHEET_LIST::UpdateSheetInstanceData( const std::vector bool + [&path]( const SCH_SHEET_INSTANCE& r ) -> bool { return path.Path() == r.m_Path; } ); diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index e9151bab63..90722605d0 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -3305,8 +3305,7 @@ int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list sheetPaths ) }, [&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath ) { - m_frame->GetToolManager()->RunAction( - SCH_ACTIONS::changeSheet, &aPath ); + m_frame->GetToolManager()->RunAction( SCH_ACTIONS::changeSheet, &aPath ); SCH_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); selectionTool->UnbrightenItem( aItem ); selectionTool->AddItemToSel( aItem, true ); @@ -3314,7 +3313,7 @@ int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list sheetPaths ) }, [&]( SCH_SHEET* aItem, SCH_SHEET_PATH aPath, SHEET_SYNCHRONIZATION_AGENT::SHEET_SYNCHRONIZATION_PLACEMENT aOp, - std::set aTemplates ) + std::set aTemplates ) { switch( aOp ) { @@ -3323,10 +3322,8 @@ int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list sheetPaths ) SCH_SHEET* sheet = static_cast( aItem ); m_dialogSyncSheetPin->Hide(); m_dialogSyncSheetPin->PreparePlacementTemplate( - sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::HIERLABEL, - aTemplates ); - m_frame->GetToolManager()->RunAction( - SCH_ACTIONS::changeSheet, &aPath ); + sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::HIERLABEL, aTemplates ); + m_frame->GetToolManager()->RunAction( SCH_ACTIONS::changeSheet, &aPath ); m_toolMgr->RunAction( SCH_ACTIONS::placeHierLabel ); break; } @@ -3335,12 +3332,9 @@ int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list sheetPaths ) SCH_SHEET* sheet = static_cast( aItem ); m_dialogSyncSheetPin->Hide(); m_dialogSyncSheetPin->PreparePlacementTemplate( - sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::SHEET_PIN, - aTemplates ); - m_frame->GetToolManager()->RunAction( - SCH_ACTIONS::changeSheet, &aPath ); - m_toolMgr->GetTool()->SyncSelection( {}, nullptr, - { sheet } ); + sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::SHEET_PIN, aTemplates ); + m_frame->GetToolManager()->RunAction( SCH_ACTIONS::changeSheet, &aPath ); + m_toolMgr->GetTool()->SyncSelection( {}, nullptr, { sheet } ); m_toolMgr->RunAction( SCH_ACTIONS::placeSheetPin ); break; } diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index b22908a3ac..b2bed1d0f9 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -154,8 +154,7 @@ int SCH_EDITOR_CONTROL::Revert( const TOOL_EVENT& aEvent ) SCH_SHEET_PATH rootSheetPath; rootSheetPath.push_back( &root ); - m_frame->GetToolManager()->RunAction( SCH_ACTIONS::changeSheet, - &rootSheetPath ); + m_frame->GetToolManager()->RunAction( SCH_ACTIONS::changeSheet, &rootSheetPath ); wxSafeYield(); } diff --git a/eeschema/tools/sch_find_replace_tool.cpp b/eeschema/tools/sch_find_replace_tool.cpp index 05aded802e..7f71b3ab2e 100644 --- a/eeschema/tools/sch_find_replace_tool.cpp +++ b/eeschema/tools/sch_find_replace_tool.cpp @@ -281,10 +281,7 @@ int SCH_FIND_REPLACE_TOOL::FindNext( const TOOL_EVENT& aEvent ) if( item ) { if( m_frame->Schematic().CurrentSheet() != sheet ) - { - m_frame->GetToolManager()->RunAction( SCH_ACTIONS::changeSheet, - &sheet ); - } + m_frame->GetToolManager()->RunAction( SCH_ACTIONS::changeSheet, &sheet ); break; } diff --git a/eeschema/tools/sch_navigate_tool.cpp b/eeschema/tools/sch_navigate_tool.cpp index 49c3f95038..68ab5eb2a8 100644 --- a/eeschema/tools/sch_navigate_tool.cpp +++ b/eeschema/tools/sch_navigate_tool.cpp @@ -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() ) 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::selectionClear ); diff --git a/eeschema/tools/sch_navigate_tool.h b/eeschema/tools/sch_navigate_tool.h index ebc00f8792..cd524f8bb5 100644 --- a/eeschema/tools/sch_navigate_tool.h +++ b/eeschema/tools/sch_navigate_tool.h @@ -80,9 +80,9 @@ private: ///< Set up handlers for various events. void setTransitions() override; ///< 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. - void changeSheet( SCH_SHEET_PATH aPath ); + void changeSheet( const SCH_SHEET_PATH& aPath ); private: std::list m_navHistory; diff --git a/eeschema/widgets/hierarchy_pane.cpp b/eeschema/widgets/hierarchy_pane.cpp index e015f5897c..a5fd19552a 100644 --- a/eeschema/widgets/hierarchy_pane.cpp +++ b/eeschema/widgets/hierarchy_pane.cpp @@ -321,8 +321,7 @@ void HIERARCHY_PANE::onSelectSheetPath( wxTreeEvent& aEvent ) return; SetCursor( wxCURSOR_ARROWWAIT ); - m_frame->GetToolManager()->RunAction( SCH_ACTIONS::changeSheet, - &itemData->m_SheetPath ); + m_frame->GetToolManager()->RunAction( SCH_ACTIONS::changeSheet, &itemData->m_SheetPath ); SetCursor( wxCURSOR_ARROW ); }