Fix defects reported by Coverity scan introduced in !1765

Corrects lifetime performance issue where extra copies of SCH_SHEET_PATH objects were being passed on the stack.
This commit is contained in:
Ethan Chien 2024-03-04 19:45:05 +00:00 committed by Seth Hillbrand
parent 62c961b8ba
commit 8cda72f8d5
4 changed files with 16 additions and 27 deletions

View File

@ -126,21 +126,9 @@ void PANEL_SYNC_SHEET_PINS::UpdateForms()
pins_list.push_back( std::make_shared<SCH_SHEET_PIN_SYNCHRONIZATION_ITEM>( pins_list.push_back( std::make_shared<SCH_SHEET_PIN_SYNCHRONIZATION_ITEM>(
static_cast<SCH_SHEET_PIN*>( pin ), m_sheet ) ); static_cast<SCH_SHEET_PIN*>( pin ), m_sheet ) );
for( const auto& [idx, model] : m_models ) m_models[SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL]->UpdateItems( std::move( labels_list ) );
{ m_models[SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN]->UpdateItems( std::move( pins_list ) );
switch( idx ) m_models[SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED]->UpdateItems( std::move( associated_list ) );
{
case SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL:
model->UpdateItems( std::move( labels_list ) );
break;
case SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN:
model->UpdateItems( std::move( pins_list ) );
break;
case SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED:
model->UpdateItems( std::move( associated_list ) );
break;
}
}
UpdatePageImage(); UpdatePageImage();
} }

View File

@ -47,16 +47,17 @@ SHEET_SYNCHRONIZATION_AGENT::SHEET_SYNCHRONIZATION_AGENT( DO_MODIFY_ITEM aDoMod
SHEET_SYNCHRONIZATION_AGENT::~SHEET_SYNCHRONIZATION_AGENT() = default; SHEET_SYNCHRONIZATION_AGENT::~SHEET_SYNCHRONIZATION_AGENT() = default;
void SHEET_SYNCHRONIZATION_AGENT::ModifyItem( SHEET_SYNCHRONIZATION_ITEM& aItem, void SHEET_SYNCHRONIZATION_AGENT::ModifyItem( SHEET_SYNCHRONIZATION_ITEM& aItem,
std::function<void()> aDoModify, std::function<void()> const& aDoModify,
SCH_SHEET_PATH const& aPath ) SCH_SHEET_PATH const& aPath )
{ {
return ModifyItem( aItem.GetItem(), aDoModify, aPath, aItem.GetKind() ); return ModifyItem( aItem.GetItem(), aDoModify, aPath, aItem.GetKind() );
} }
void SHEET_SYNCHRONIZATION_AGENT::ModifyItem( SCH_ITEM* sch_item, std::function<void()> aDoModify, void SHEET_SYNCHRONIZATION_AGENT::ModifyItem( SCH_ITEM* sch_item,
const SCH_SHEET_PATH& aPath, std::function<void()> const& aDoModify,
const SCH_SHEET_PATH& aPath,
SHEET_SYNCHRONIZATION_ITEM_KIND aKind ) SHEET_SYNCHRONIZATION_ITEM_KIND aKind )
{ {
if( !aDoModify ) if( !aDoModify )
@ -100,7 +101,7 @@ void SHEET_SYNCHRONIZATION_AGENT::RemoveItem( SHEET_SYNCHRONIZATION_ITEM& aItem,
{ {
SCH_SHEET_PATH path_cp = aPath; SCH_SHEET_PATH path_cp = aPath;
path_cp.pop_back(); path_cp.pop_back();
m_doDelete( aItem.GetItem(), path_cp ); m_doDelete( aItem.GetItem(), std::move( path_cp ) );
break; break;
} }
case SHEET_SYNCHRONIZATION_ITEM_KIND::HIERLABEL_AND_SHEET_PIN: case SHEET_SYNCHRONIZATION_ITEM_KIND::HIERLABEL_AND_SHEET_PIN:

View File

@ -56,7 +56,7 @@ public:
using MODIFICATION = std::function<void()>; using MODIFICATION = std::function<void()>;
using DO_MODIFY_ITEM = std::function<void( EDA_ITEM*, SCH_SHEET_PATH, MODIFICATION )>; using DO_MODIFY_ITEM = std::function<void( EDA_ITEM*, SCH_SHEET_PATH, MODIFICATION const& )>;
using DO_PLACE_ITEM = std::function<void( SCH_SHEET*, SCH_SHEET_PATH, using DO_PLACE_ITEM = std::function<void( SCH_SHEET*, SCH_SHEET_PATH,
SHEET_SYNCHRONIZATION_PLACEMENT, EDA_ITEM* )>; SHEET_SYNCHRONIZATION_PLACEMENT, EDA_ITEM* )>;
@ -67,11 +67,11 @@ public:
SCH_EDIT_FRAME* a_frame ); SCH_EDIT_FRAME* a_frame );
~SHEET_SYNCHRONIZATION_AGENT(); ~SHEET_SYNCHRONIZATION_AGENT();
void ModifyItem( SHEET_SYNCHRONIZATION_ITEM& aItem, std::function<void()> aDoModify, void ModifyItem( SHEET_SYNCHRONIZATION_ITEM& aItem, std::function<void()> const& aDoModify,
const SCH_SHEET_PATH& aPath ); const SCH_SHEET_PATH& aPath );
void ModifyItem( SCH_ITEM* aItem, std::function<void()> aDoModify, const SCH_SHEET_PATH& aPath, void ModifyItem( SCH_ITEM* aItem, std::function<void()> const& aDoModify,
SHEET_SYNCHRONIZATION_ITEM_KIND aKind ); const SCH_SHEET_PATH& aPath, SHEET_SYNCHRONIZATION_ITEM_KIND aKind );
void RemoveItem( SHEET_SYNCHRONIZATION_ITEM& aItem, SCH_SHEET* aSheet, void RemoveItem( SHEET_SYNCHRONIZATION_ITEM& aItem, SCH_SHEET* aSheet,
SCH_SHEET_PATH const& aPath ); SCH_SHEET_PATH const& aPath );

View File

@ -2486,7 +2486,7 @@ int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list<SCH_SHEET_PATH> sheetPaths )
m_frame, std::move( sheetPaths ), m_frame, std::move( sheetPaths ),
std::make_shared<SHEET_SYNCHRONIZATION_AGENT>( std::make_shared<SHEET_SYNCHRONIZATION_AGENT>(
[&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath, [&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath,
SHEET_SYNCHRONIZATION_AGENT::MODIFICATION aModify ) SHEET_SYNCHRONIZATION_AGENT::MODIFICATION const& aModify )
{ {
SCH_COMMIT commit( m_toolMgr ); SCH_COMMIT commit( m_toolMgr );
@ -2609,7 +2609,7 @@ int SCH_DRAWING_TOOLS::SyncAllSheetsPins( const TOOL_EVENT& aEvent )
SCH_SHEET_PATH current; SCH_SHEET_PATH current;
current.push_back( &m_frame->Schematic().Root() ); current.push_back( &m_frame->Schematic().Root() );
getSheetChildren( sheetPaths, m_frame->Schematic().Root().GetScreen(), visited, current ); getSheetChildren( sheetPaths, m_frame->Schematic().Root().GetScreen(), visited, current );
return doSyncSheetsPins( sheetPaths ); return doSyncSheetsPins( std::move( sheetPaths ) );
} }