Replace inserts/push_backs with emplace in some spots

This commit is contained in:
Marek Roszko 2022-02-05 19:53:31 -05:00
parent 4e3109a633
commit 41f54349a5
19 changed files with 54 additions and 64 deletions

View File

@ -304,8 +304,7 @@ SCENEGRAPH* S3D_CACHE::checkCache( const wxString& aFileName, S3D_CACHE_ENTRY**
// or we do not have a configured cache file directory, we create an // or we do not have a configured cache file directory, we create an
// entry to prevent further attempts at loading the file // entry to prevent further attempts at loading the file
if( m_CacheMap.insert( std::pair< wxString, S3D_CACHE_ENTRY* > if( m_CacheMap.emplace( aFileName, ep ).second == false )
( aFileName, ep ) ).second == false )
{ {
wxLogTrace( MASK_3D_CACHE, wxLogTrace( MASK_3D_CACHE,
wxT( "%s:%s:%d\n * [BUG] duplicate entry in map file; key = '%s'" ), wxT( "%s:%s:%d\n * [BUG] duplicate entry in map file; key = '%s'" ),
@ -323,8 +322,7 @@ SCENEGRAPH* S3D_CACHE::checkCache( const wxString& aFileName, S3D_CACHE_ENTRY**
return nullptr; return nullptr;
} }
if( m_CacheMap.insert( std::pair< wxString, S3D_CACHE_ENTRY* > if( m_CacheMap.emplace( aFileName, ep ).second == false )
( aFileName, ep ) ).second == false )
{ {
wxLogTrace( MASK_3D_CACHE, wxLogTrace( MASK_3D_CACHE,
wxT( "%s:%s:%d\n * [BUG] duplicate entry in map file; key = '%s'" ), wxT( "%s:%s:%d\n * [BUG] duplicate entry in map file; key = '%s'" ),

View File

@ -55,7 +55,7 @@
S3D_PLUGIN_MANAGER::S3D_PLUGIN_MANAGER() S3D_PLUGIN_MANAGER::S3D_PLUGIN_MANAGER()
{ {
// create the initial file filter list entry // create the initial file filter list entry
m_FileFilters.push_back( _( "All Files" ) + wxT( " (*.*)|*.*" ) ); m_FileFilters.emplace_back( _( "All Files" ) + wxT( " (*.*)|*.*" ) );
// discover and load plugins // discover and load plugins
loadPlugins(); loadPlugins();
@ -391,7 +391,7 @@ void S3D_PLUGIN_MANAGER::addExtensionMap( KICAD_PLUGIN_LDR_3D* aPlugin )
if( !ws.empty() ) if( !ws.empty() )
{ {
m_ExtMap.insert( std::pair< const wxString, KICAD_PLUGIN_LDR_3D* >( ws, aPlugin ) ); m_ExtMap.emplace( ws, aPlugin );
} }
} }

View File

@ -359,7 +359,7 @@ S3DMODEL* S3D::GetModel( SCENEGRAPH* aNode )
app.transparency = 0.0f; app.transparency = 0.0f;
materials.matorder.push_back( &app ); materials.matorder.push_back( &app );
materials.matmap.insert( std::pair< SGAPPEARANCE const*, int >( &app, 0 ) ); materials.matmap.emplace( &app, 0 );
if( aNode->Prepare( nullptr, materials, meshes ) ) if( aNode->Prepare( nullptr, materials, meshes ) )
{ {

View File

@ -420,8 +420,7 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
} }
else else
{ {
vmap.insert( std::pair < int, std::list < glm::dvec3 > > vmap.emplace( p1, std::list < glm::dvec3 >( 1, tri ) );
( p1, std::list < glm::dvec3 >( 1, tri ) ) );
} }
ip = vmap.find( p2 ); ip = vmap.find( p2 );
@ -432,8 +431,7 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
} }
else else
{ {
vmap.insert( std::pair < int, std::list < glm::dvec3 > > vmap.emplace( p2, std::list < glm::dvec3 >( 1, tri ) );
( p2, std::list < glm::dvec3 >( 1, tri ) ) );
} }
ip = vmap.find( p3 ); ip = vmap.find( p3 );
@ -444,8 +442,7 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
} }
else else
{ {
vmap.insert( std::pair < int, std::list < glm::dvec3 > > vmap.emplace( p3, std::list < glm::dvec3 >( 1, tri ) );
( p3, std::list < glm::dvec3 >( 1, tri ) ) );
} }
} }

View File

@ -260,7 +260,7 @@ bool S3D::GetMatIndex( MATLIST& aList, SGNODE* aNode, int& aIndex )
int idx = (int)aList.matorder.size(); int idx = (int)aList.matorder.size();
aList.matorder.push_back( node ); aList.matorder.push_back( node );
aList.matmap.insert( std::pair< SGAPPEARANCE const*, int >( node, idx ) ); aList.matmap.emplace( node, idx );
aIndex = idx; aIndex = idx;
return true; return true;

View File

@ -699,7 +699,7 @@ bool SGSHAPE::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
if( mit == indexmap.end() ) if( mit == indexmap.end() )
{ {
indexmap.insert( std::pair< int, unsigned int >( lv[i], vertices.size() ) ); indexmap.emplace( lv[i], vertices.size() );
vertices.push_back( lv[i] ); vertices.push_back( lv[i] );
} }
} }

View File

@ -136,7 +136,7 @@ BOARD_ADAPTER::BOARD_ADAPTER() :
if( !g_ColorsLoaded ) if( !g_ColorsLoaded )
{ {
#define ADD_COLOR( list, r, g, b, a, name ) \ #define ADD_COLOR( list, r, g, b, a, name ) \
list.push_back( CUSTOM_COLOR_ITEM( r/255.0, g/255.0, b/255.0, a, name ) ) list.emplace_back( r/255.0, g/255.0, b/255.0, a, name )
ADD_COLOR( g_SilkscreenColors, 245, 245, 245, 1.0, NotSpecifiedPrm() ); // White ADD_COLOR( g_SilkscreenColors, 245, 245, 245, 1.0, NotSpecifiedPrm() ); // White
ADD_COLOR( g_SilkscreenColors, 20, 51, 36, 1.0, wxT( "Green" ) ); ADD_COLOR( g_SilkscreenColors, 20, 51, 36, 1.0, wxT( "Green" ) );

View File

@ -200,7 +200,7 @@ void FONTCONFIG::ListFonts( std::vector<std::string>& aFonts )
std::map<std::string, FONTINFO>::iterator it = m_fonts.find( theFamily ); std::map<std::string, FONTINFO>::iterator it = m_fonts.find( theFamily );
if( it == m_fonts.end() ) if( it == m_fonts.end() )
m_fonts.insert( std::pair<std::string, FONTINFO>( theFamily, fontInfo ) ); m_fonts.emplace( theFamily, fontInfo );
else else
it->second.Children().push_back( fontInfo ); it->second.Children().push_back( fontInfo );
} }

View File

@ -488,7 +488,7 @@ std::string FormatProbeItems( bool aSelectConnections, const std::deque<EDA_ITEM
wxString ref = symbol->GetField( REFERENCE_FIELD )->GetText(); wxString ref = symbol->GetField( REFERENCE_FIELD )->GetText();
parts.insert( wxT( "F" ) + EscapeString( ref, CTX_IPC ) ); parts.emplace( wxT( "F" ) + EscapeString( ref, CTX_IPC ) );
break; break;
} }
@ -515,7 +515,7 @@ std::string FormatProbeItems( bool aSelectConnections, const std::deque<EDA_ITEM
full_path += "/" + sheet->m_Uuid.AsString(); full_path += "/" + sheet->m_Uuid.AsString();
parts.insert( wxT( "S" ) + full_path ); parts.emplace( wxT( "S" ) + full_path );
break; break;
} }

View File

@ -100,7 +100,7 @@ double AM_PARAM::GetValue( const D_CODE* aDcode ) const
case OPEN_PAR: case OPEN_PAR:
case CLOSE_PAR: // Priority modifiers: store in stack case CLOSE_PAR: // Priority modifiers: store in stack
op_code = item.GetType(); op_code = item.GetType();
ops.push_back( AM_PARAM_EVAL( op_code ) ); ops.emplace_back( op_code );
break; break;
case PUSHPARM: case PUSHPARM:
@ -122,12 +122,12 @@ double AM_PARAM::GetValue( const D_CODE* aDcode ) const
wxFAIL_MSG( wxT( "AM_PARAM::GetValue(): NULL param aDcode" ) ); wxFAIL_MSG( wxT( "AM_PARAM::GetValue(): NULL param aDcode" ) );
} }
ops.push_back( AM_PARAM_EVAL( curr_value ) ); ops.emplace_back( curr_value );
break; break;
case PUSHVALUE: // a value is on the stack: case PUSHVALUE: // a value is on the stack:
curr_value = item.GetValue(); curr_value = item.GetValue();
ops.push_back( AM_PARAM_EVAL( curr_value ) ); ops.emplace_back( curr_value );
break; break;
default: default:

View File

@ -397,9 +397,9 @@ void TransformTrapezoidToPolygon( SHAPE_POLY_SET& aCornerBuffer, const VECTOR2I&
if( aDeltaX > size.y ) // shrinking turned the trapezoid into a triangle if( aDeltaX > size.y ) // shrinking turned the trapezoid into a triangle
{ {
corners.reserve( 3 ); corners.reserve( 3 );
corners.push_back( ROUNDED_CORNER( -size.x, -size.y - aDeltaX ) ); corners.emplace_back( -size.x, -size.y - aDeltaX );
corners.push_back( ROUNDED_CORNER( KiROUND( size.y / slope ), 0 ) ); corners.emplace_back( KiROUND( size.y / slope ), 0 );
corners.push_back( ROUNDED_CORNER( -size.x, size.y + aDeltaX ) ); corners.emplace_back( -size.x, size.y + aDeltaX );
} }
} }
else // vertical trapezoid else // vertical trapezoid
@ -413,9 +413,9 @@ void TransformTrapezoidToPolygon( SHAPE_POLY_SET& aCornerBuffer, const VECTOR2I&
if( aDeltaY > size.x ) if( aDeltaY > size.x )
{ {
corners.reserve( 3 ); corners.reserve( 3 );
corners.push_back( ROUNDED_CORNER( 0, -KiROUND( size.x / slope ) ) ); corners.emplace_back( 0, -KiROUND( size.x / slope ) );
corners.push_back( ROUNDED_CORNER( size.x + aDeltaY, size.y ) ); corners.emplace_back( size.x + aDeltaY, size.y );
corners.push_back( ROUNDED_CORNER( -size.x - aDeltaY, size.y ) ); corners.emplace_back( -size.x - aDeltaY, size.y );
} }
} }
@ -425,10 +425,10 @@ void TransformTrapezoidToPolygon( SHAPE_POLY_SET& aCornerBuffer, const VECTOR2I&
if( corners.empty() ) if( corners.empty() )
{ {
corners.reserve( 4 ); corners.reserve( 4 );
corners.push_back( ROUNDED_CORNER( -size.x + aDeltaY, -size.y - aDeltaX ) ); corners.emplace_back( -size.x + aDeltaY, -size.y - aDeltaX );
corners.push_back( ROUNDED_CORNER( size.x - aDeltaY, -size.y + aDeltaX ) ); corners.emplace_back( size.x - aDeltaY, -size.y + aDeltaX );
corners.push_back( ROUNDED_CORNER( size.x + aDeltaY, size.y - aDeltaX ) ); corners.emplace_back( size.x + aDeltaY, size.y - aDeltaX );
corners.push_back( ROUNDED_CORNER( -size.x - aDeltaY, size.y + aDeltaX ) ); corners.emplace_back( -size.x - aDeltaY, size.y + aDeltaX );
if( aDeltaY == size.x || aDeltaX == size.y ) if( aDeltaY == size.x || aDeltaX == size.y )
CornerListRemoveDuplicates( corners ); CornerListRemoveDuplicates( corners );
@ -466,10 +466,10 @@ void TransformRoundChamferedRectToPolygon( SHAPE_POLY_SET& aCornerBuffer, const
std::vector<ROUNDED_CORNER> corners; std::vector<ROUNDED_CORNER> corners;
corners.reserve( 4 + chamferCnt ); corners.reserve( 4 + chamferCnt );
corners.push_back( ROUNDED_CORNER( -size.x, -size.y, aCornerRadius ) ); corners.emplace_back( -size.x, -size.y, aCornerRadius );
corners.push_back( ROUNDED_CORNER( size.x, -size.y, aCornerRadius ) ); corners.emplace_back( size.x, -size.y, aCornerRadius );
corners.push_back( ROUNDED_CORNER( size.x, size.y, aCornerRadius ) ); corners.emplace_back( size.x, size.y, aCornerRadius );
corners.push_back( ROUNDED_CORNER( -size.x, size.y, aCornerRadius ) ); corners.emplace_back( -size.x, size.y, aCornerRadius );
if( aChamferCorners ) if( aChamferCorners )
{ {

View File

@ -116,7 +116,7 @@ ClipperLib::Path SHAPE_LINE_CHAIN::convertToClipper( bool aRequiredOrientation,
size_t z_value_ptr = aZValueBuffer.size(); size_t z_value_ptr = aZValueBuffer.size();
aZValueBuffer.push_back( z_value ); aZValueBuffer.push_back( z_value );
c_path.push_back( ClipperLib::IntPoint( vertex.x, vertex.y, z_value_ptr ) ); c_path.emplace_back( vertex.x, vertex.y, z_value_ptr );
} }
aArcBuffer.insert( aArcBuffer.end(), input.m_arcs.begin(), input.m_arcs.end() ); aArcBuffer.insert( aArcBuffer.end(), input.m_arcs.begin(), input.m_arcs.end() );

View File

@ -815,8 +815,8 @@ void CONNECTIVITY_DATA::SetProgressReporter( PROGRESS_REPORTER* aReporter )
void CONNECTIVITY_DATA::AddExclusion( const KIID& aBoardItemId1, const KIID& aBoardItemId2 ) void CONNECTIVITY_DATA::AddExclusion( const KIID& aBoardItemId1, const KIID& aBoardItemId2 )
{ {
m_exclusions.insert( std::pair<KIID, KIID>( aBoardItemId1, aBoardItemId2 ) ); m_exclusions.emplace( aBoardItemId1, aBoardItemId2 );
m_exclusions.insert( std::pair<KIID, KIID>( aBoardItemId2, aBoardItemId1 ) ); m_exclusions.emplace( aBoardItemId2, aBoardItemId1 );
for( RN_NET* rnNet : m_nets ) for( RN_NET* rnNet : m_nets )
{ {

View File

@ -103,7 +103,7 @@ public:
void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction, void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction,
const wxString& aPinType ) const wxString& aPinType )
{ {
m_nets.push_back( COMPONENT_NET( aPinName, aNetName, aPinFunction, aPinType ) ); m_nets.emplace_back( aPinName, aNetName, aPinFunction, aPinType );
} }
unsigned GetNetCount() const { return m_nets.size(); } unsigned GetNetCount() const { return m_nets.size(); }

View File

@ -259,7 +259,7 @@ struct DATA
app.SetSpecular( 0.12f, 0.12f, 0.12f ); app.SetSpecular( 0.12f, 0.12f, 0.12f );
app.SetAmbient( 0.1f, 0.1f, 0.1f ); app.SetAmbient( 0.1f, 0.1f, 0.1f );
app.SetDiffuse( colorObj->Red(), colorObj->Green(), colorObj->Blue() ); app.SetDiffuse( colorObj->Red(), colorObj->Green(), colorObj->Blue() );
colors.insert( std::pair< Standard_Real, SGNODE* >( id, app.GetRawPtr() ) ); colors.emplace( id, app.GetRawPtr() );
return app.GetRawPtr(); return app.GetRawPtr();
} }
@ -1167,7 +1167,7 @@ bool processFace( const TopoDS_Face& face, DATA& data, SGNODE* parent,
vshape.SetParent( parent ); vshape.SetParent( parent );
if( !partID.empty() ) if( !partID.empty() )
data.faces.insert( std::pair< std::string, SGNODE* >( partID, vshape.GetRawPtr() ) ); data.faces.emplace( partID, vshape.GetRawPtr() );
// The outer surface of an IGES model is indeterminate so // The outer surface of an IGES model is indeterminate so
// we must render both sides of a surface. // we must render both sides of a surface.
@ -1187,7 +1187,7 @@ bool processFace( const TopoDS_Face& face, DATA& data, SGNODE* parent,
vshape2.SetParent( parent ); vshape2.SetParent( parent );
if( !partID.empty() ) if( !partID.empty() )
data.faces.insert( std::pair< std::string, SGNODE* >( id2, vshape2.GetRawPtr() ) ); data.faces.emplace( id2, vshape2.GetRawPtr() );
} }
return true; return true;

View File

@ -46,7 +46,7 @@ bool NAMEREGISTER::AddName( const std::string& aName, WRL1NODE* aNode )
if( ir != reg.end() ) if( ir != reg.end() )
reg.erase( ir ); reg.erase( ir );
reg.insert( std::pair< std::string, WRL1NODE* >( aName, aNode ) ); reg.emplace( aName, aNode );
return true; return true;
} }

View File

@ -130,7 +130,7 @@ SGNODE* WRL2BASE::GetInlineData( const std::string& aName )
if( !fn.Normalize() ) if( !fn.Normalize() )
{ {
m_inlineModels.insert( std::pair< std::string, SGNODE* >( aName, nullptr ) ); m_inlineModels.emplace( aName, nullptr );
return nullptr; return nullptr;
} }
@ -138,11 +138,11 @@ SGNODE* WRL2BASE::GetInlineData( const std::string& aName )
if( nullptr == sp ) if( nullptr == sp )
{ {
m_inlineModels.insert( std::pair< std::string, SGNODE* >( aName, nullptr ) ); m_inlineModels.emplace( aName, nullptr );
return nullptr; return nullptr;
} }
m_inlineModels.insert( std::pair< std::string, SGNODE* >( aName, (SGNODE*)sp ) ); m_inlineModels.emplace( aName, (SGNODE*) sp );
return (SGNODE*)sp; return (SGNODE*)sp;
} }

View File

@ -42,7 +42,7 @@ bool X3D_DICT::AddName( const wxString& aName, X3DNODE* aNode )
if( ir != reg.end() ) if( ir != reg.end() )
reg.erase( ir ); reg.erase( ir );
reg.insert( std::pair< wxString, X3DNODE* >( aName, aNode ) ); reg.emplace( aName, aNode );
return true; return true;
} }

View File

@ -2026,8 +2026,7 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo
} }
} }
if( olnOther.insert( pair<string, if( olnOther.emplace( op->GetOutlineIdentifier(), op ).second == false )
OTHER_OUTLINE*>(op->GetOutlineIdentifier(), op ) ).second == false )
{ {
ostringstream ostr; ostringstream ostr;
ostr << "invalid IDF file\n"; ostr << "invalid IDF file\n";
@ -2277,7 +2276,7 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo
} }
} }
olnGroup.insert( pair<string, GROUP_OUTLINE*>(op->GetGroupName(), op) ); olnGroup.emplace( op->GetGroupName(), op );
return; return;
} }
@ -2551,8 +2550,7 @@ void IDF3_BOARD::readLibSection( std::istream& aLibFile, IDF3::FILE_STATE& aLibS
if( cop == nullptr ) if( cop == nullptr )
{ {
compOutlines.insert( pair<const std::string, compOutlines.emplace( pout->GetUID(), pout );
IDF3_COMP_OUTLINE*>( pout->GetUID(), pout ) );
} }
else else
{ {
@ -3751,8 +3749,7 @@ IDF_DRILL_DATA* IDF3_BOARD::addCompDrill( double aDia, double aXpos, double aYpo
comp->SetParent( this ); comp->SetParent( this );
comp->SetRefDes( refdes ); comp->SetRefDes( refdes );
ref = components.insert( std::pair< std::string, ref = components.emplace( comp->GetRefDes(), comp ).first;
IDF3_COMPONENT*> ( comp->GetRefDes(), comp ) ).first;
} }
// add the drill // add the drill
@ -3812,8 +3809,7 @@ IDF_DRILL_DATA* IDF3_BOARD::addCompDrill( IDF_DRILL_DATA* aDrilledHole )
comp->SetParent( this ); comp->SetParent( this );
comp->SetRefDes( aDrilledHole->GetDrillRefDes() ); comp->SetRefDes( aDrilledHole->GetDrillRefDes() );
ref = components.insert( std::pair< std::string, ref = components.emplace( comp->GetRefDes(), comp ).first;
IDF3_COMPONENT*> ( comp->GetRefDes(), comp ) ).first;
} }
IDF_DRILL_DATA* dp = ref->second->AddDrill( aDrilledHole ); IDF_DRILL_DATA* dp = ref->second->AddDrill( aDrilledHole );
@ -3859,8 +3855,7 @@ bool IDF3_BOARD::AddComponent( IDF3_COMPONENT* aComponent )
return false; return false;
} }
if( components.insert( std::pair<std::string, IDF3_COMPONENT*> if( components.emplace( aComponent->GetRefDes(), aComponent ).second == false )
( aComponent->GetRefDes(), aComponent ) ).second == false )
{ {
ostringstream ostr; ostringstream ostr;
ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "(): \n"; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "(): \n";
@ -4086,7 +4081,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam
delete cp; delete cp;
// make sure we can find the item via its filename // make sure we can find the item via its filename
uidFileList.insert( std::pair< std::string, std::string>( fname, uid ) ); uidFileList.emplace( fname, uid );
// return the pointer to the original // return the pointer to the original
return oldp; return oldp;
@ -4114,8 +4109,8 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam
if( oldp == nullptr ) if( oldp == nullptr )
{ {
// everything is fine, there are no existing entries // everything is fine, there are no existing entries
uidFileList.insert( std::pair< std::string, std::string>( fname, uid ) ); uidFileList.emplace( fname, uid );
compOutlines.insert( pair<const std::string, IDF3_COMP_OUTLINE*>( uid, cp ) ); compOutlines.emplace( uid, cp );
return cp; return cp;
} }
@ -4126,7 +4121,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam
delete cp; delete cp;
// make sure we can find the item via its other filename // make sure we can find the item via its other filename
uidFileList.insert( std::pair< std::string, std::string>( fname, uid ) ); uidFileList.emplace( fname, uid );
// return the pointer to the original // return the pointer to the original
return oldp; return oldp;
@ -4212,7 +4207,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetInvalidOutline( const std::string& aGeomName,
else else
cp->CreateDefaultOutline( aGeomName, aPartName ); cp->CreateDefaultOutline( aGeomName, aPartName );
compOutlines.insert( pair<const std::string, IDF3_COMP_OUTLINE*>(cp->GetUID(), cp) ); compOutlines.emplace( cp->GetUID(), cp );
return cp; return cp;
} }