Avoid copies when using auto

This commit is contained in:
Ian McInerney 2024-12-31 00:03:37 +00:00
parent 906c2f3d49
commit c0622eaa45
6 changed files with 17 additions and 15 deletions

View File

@ -639,8 +639,9 @@ std::map<int, COLOR4D> BOARD_ADAPTER::GetLayerColors() const
const BOARD_STACKUP& stackup = m_board->GetDesignSettings().GetStackupDescriptor(); const BOARD_STACKUP& stackup = m_board->GetDesignSettings().GetStackupDescriptor();
KIGFX::COLOR4D bodyColor( 0, 0, 0, 0 ); KIGFX::COLOR4D bodyColor( 0, 0, 0, 0 );
// Can't do a const KIGFX::COLOR4D& return type here because there are temporary variables
auto findColor = auto findColor =
[]( const wxString& aColorName, const CUSTOM_COLORS_LIST& aColorSet ) []( const wxString& aColorName, const CUSTOM_COLORS_LIST& aColorSet ) -> const KIGFX::COLOR4D
{ {
if( aColorName.StartsWith( wxT( "#" ) ) ) if( aColorName.StartsWith( wxT( "#" ) ) )
{ {

View File

@ -215,7 +215,7 @@ void LISTBOX_TRICKS::OnListBoxRDown( wxMouseEvent& aEvent )
{ {
wxMenu menu; wxMenu menu;
const auto mstr = [&]( const MENU_ID& id ) const auto mstr = [&]( const MENU_ID& id ) -> const wxString&
{ {
return m_menuStrings[id]; return m_menuStrings[id];
}; };

View File

@ -65,7 +65,7 @@ public:
return m_categoryDescriptions.at( aCategoryName ); return m_categoryDescriptions.at( aCategoryName );
} }
auto getCachedParts() { return m_cache; } auto& getCachedParts() { return m_cache; }
private: private:
// This is clunky but at the moment the only way to free the pointer after use without KiCad crashing. // This is clunky but at the moment the only way to free the pointer after use without KiCad crashing.

View File

@ -131,8 +131,9 @@ EXPORTER_PCB_VRML::EXPORTER_PCB_VRML( BOARD* aBoard ) :
const BOARD_STACKUP& stackup = m_board->GetDesignSettings().GetStackupDescriptor(); const BOARD_STACKUP& stackup = m_board->GetDesignSettings().GetStackupDescriptor();
// Can't do a const KIGFX::COLOR4D& return type here because there are temporary variables
auto findColor = auto findColor =
[]( const wxString& aColorName, const CUSTOM_COLORS_LIST& aColorSet ) []( const wxString& aColorName, const CUSTOM_COLORS_LIST& aColorSet ) -> const KIGFX::COLOR4D
{ {
if( aColorName.StartsWith( wxT( "#" ) ) ) if( aColorName.StartsWith( wxT( "#" ) ) )
{ {

View File

@ -2282,8 +2282,8 @@ int DRAWING_TOOL::PlaceTuningPattern( const TOOL_EVENT& aEvent )
auto applyCommonSettings = [&]( PCB_TUNING_PATTERN* aPattern ) auto applyCommonSettings = [&]( PCB_TUNING_PATTERN* aPattern )
{ {
auto origTargetLength = aPattern->GetSettings().m_targetLength; const auto& origTargetLength = aPattern->GetSettings().m_targetLength;
auto origTargetSkew = aPattern->GetSettings().m_targetSkew; const auto& origTargetSkew = aPattern->GetSettings().m_targetSkew;
aPattern->GetSettings() = meanderSettings; aPattern->GetSettings() = meanderSettings;

View File

@ -557,7 +557,7 @@ bool MULTI_DRAGGER::multidragMarkObstacles( std::vector<MDRAG_LINE>& aCompletedL
{ {
for( int l2 = l1 + 1; l2 < aCompletedLines.size(); l2++ ) for( int l2 = l1 + 1; l2 < aCompletedLines.size(); l2++ )
{ {
auto l1l = aCompletedLines[l1].draggedLine; const auto& l1l = aCompletedLines[l1].draggedLine;
auto l2l = aCompletedLines[l2].draggedLine; auto l2l = aCompletedLines[l2].draggedLine;
if( clipToOtherLine( m_lastNode, l1l, l2l ) ) if( clipToOtherLine( m_lastNode, l1l, l2l ) )