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>(
static_cast<SCH_SHEET_PIN*>( pin ), m_sheet ) );
for( const auto& [idx, model] : m_models )
{
switch( idx )
{
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;
}
}
m_models[SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL]->UpdateItems( std::move( labels_list ) );
m_models[SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN]->UpdateItems( std::move( pins_list ) );
m_models[SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED]->UpdateItems( std::move( associated_list ) );
UpdatePageImage();
}

View File

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

View File

@ -56,7 +56,7 @@ public:
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,
SHEET_SYNCHRONIZATION_PLACEMENT, EDA_ITEM* )>;
@ -67,11 +67,11 @@ public:
SCH_EDIT_FRAME* a_frame );
~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 );
void ModifyItem( SCH_ITEM* aItem, std::function<void()> aDoModify, const SCH_SHEET_PATH& aPath,
SHEET_SYNCHRONIZATION_ITEM_KIND aKind );
void ModifyItem( SCH_ITEM* aItem, std::function<void()> const& aDoModify,
const SCH_SHEET_PATH& aPath, SHEET_SYNCHRONIZATION_ITEM_KIND aKind );
void RemoveItem( SHEET_SYNCHRONIZATION_ITEM& aItem, SCH_SHEET* aSheet,
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 ),
std::make_shared<SHEET_SYNCHRONIZATION_AGENT>(
[&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath,
SHEET_SYNCHRONIZATION_AGENT::MODIFICATION aModify )
SHEET_SYNCHRONIZATION_AGENT::MODIFICATION const& aModify )
{
SCH_COMMIT commit( m_toolMgr );
@ -2609,7 +2609,7 @@ int SCH_DRAWING_TOOLS::SyncAllSheetsPins( const TOOL_EVENT& aEvent )
SCH_SHEET_PATH current;
current.push_back( &m_frame->Schematic().Root() );
getSheetChildren( sheetPaths, m_frame->Schematic().Root().GetScreen(), visited, current );
return doSyncSheetsPins( sheetPaths );
return doSyncSheetsPins( std::move( sheetPaths ) );
}