From edd94ce2d6d8b064f4184219ceb77e99199302ec Mon Sep 17 00:00:00 2001 From: John Beard Date: Wed, 27 Mar 2019 09:39:25 +0000 Subject: [PATCH] Eeschema: internal tidying of field editor ApplyData Make a few things const (specficially the reference into m_fieldStore - we should commit to not modifying that in this function. Also avoid a couple of needless string copies. Also explicitly dereference the into a (non-const) reference at the outset. For the whole if this function, comp is the same object and may not be null (as it is used unchecked). --- .../dialogs/dialog_fields_editor_global.cpp | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index f68dc6d5c6..2099dd2099 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -590,26 +590,29 @@ public: { for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i ) { - SCH_COMPONENT* comp = m_componentRefs[ i ].GetComp(); + SCH_COMPONENT& comp = *m_componentRefs[i].GetComp(); - m_frame->SetCurrentSheet( m_componentRefs[ i ].GetSheetPath() ); - m_frame->SaveCopyInUndoList( comp, UR_CHANGED, true ); + m_frame->SetCurrentSheet( m_componentRefs[i].GetSheetPath() ); + m_frame->SaveCopyInUndoList( &comp, UR_CHANGED, true ); - std::map& fieldStore = m_dataStore[ comp->GetTimeStamp() ]; + const std::map& fieldStore = m_dataStore[comp.GetTimeStamp()]; - for( std::pair srcData : fieldStore ) + for( const std::pair srcData : fieldStore ) { - wxString srcName = srcData.first; - wxString srcValue = srcData.second; - SCH_FIELD* destField = comp->FindField( srcName ); + const wxString& srcName = srcData.first; + const wxString& srcValue = srcData.second; + SCH_FIELD* destField = comp.FindField( srcName ); if( !destField && !srcValue.IsEmpty() ) - destField = comp->AddField( SCH_FIELD( comp->GetPosition(), -1, comp, srcName ) ); + { + const auto compOrigin = comp.GetPosition(); + destField = comp.AddField( SCH_FIELD( compOrigin, -1, &comp, srcName ) ); + } if( destField && !srcValue.IsEmpty() ) destField->SetText( srcValue ); else - comp->RemoveField( srcName ); + comp.RemoveField( srcName ); } }