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
// entry to prevent further attempts at loading the file
if( m_CacheMap.insert( std::pair< wxString, S3D_CACHE_ENTRY* >
( aFileName, ep ) ).second == false )
if( m_CacheMap.emplace( aFileName, ep ).second == false )
{
wxLogTrace( MASK_3D_CACHE,
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;
}
if( m_CacheMap.insert( std::pair< wxString, S3D_CACHE_ENTRY* >
( aFileName, ep ) ).second == false )
if( m_CacheMap.emplace( aFileName, ep ).second == false )
{
wxLogTrace( MASK_3D_CACHE,
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()
{
// 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
loadPlugins();
@ -391,7 +391,7 @@ void S3D_PLUGIN_MANAGER::addExtensionMap( KICAD_PLUGIN_LDR_3D* aPlugin )
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;
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 ) )
{

View File

@ -420,8 +420,7 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
}
else
{
vmap.insert( std::pair < int, std::list < glm::dvec3 > >
( p1, std::list < glm::dvec3 >( 1, tri ) ) );
vmap.emplace( p1, std::list < glm::dvec3 >( 1, tri ) );
}
ip = vmap.find( p2 );
@ -432,8 +431,7 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
}
else
{
vmap.insert( std::pair < int, std::list < glm::dvec3 > >
( p2, std::list < glm::dvec3 >( 1, tri ) ) );
vmap.emplace( p2, std::list < glm::dvec3 >( 1, tri ) );
}
ip = vmap.find( p3 );
@ -444,8 +442,7 @@ bool S3D::CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >
}
else
{
vmap.insert( std::pair < int, std::list < glm::dvec3 > >
( p3, std::list < glm::dvec3 >( 1, tri ) ) );
vmap.emplace( 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();
aList.matorder.push_back( node );
aList.matmap.insert( std::pair< SGAPPEARANCE const*, int >( node, idx ) );
aList.matmap.emplace( node, idx );
aIndex = idx;
return true;

View File

@ -699,7 +699,7 @@ bool SGSHAPE::Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
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] );
}
}

View File

@ -136,7 +136,7 @@ BOARD_ADAPTER::BOARD_ADAPTER() :
if( !g_ColorsLoaded )
{
#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, 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 );
if( it == m_fonts.end() )
m_fonts.insert( std::pair<std::string, FONTINFO>( theFamily, fontInfo ) );
m_fonts.emplace( theFamily, fontInfo );
else
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();
parts.insert( wxT( "F" ) + EscapeString( ref, CTX_IPC ) );
parts.emplace( wxT( "F" ) + EscapeString( ref, CTX_IPC ) );
break;
}
@ -515,7 +515,7 @@ std::string FormatProbeItems( bool aSelectConnections, const std::deque<EDA_ITEM
full_path += "/" + sheet->m_Uuid.AsString();
parts.insert( wxT( "S" ) + full_path );
parts.emplace( wxT( "S" ) + full_path );
break;
}

View File

@ -100,7 +100,7 @@ double AM_PARAM::GetValue( const D_CODE* aDcode ) const
case OPEN_PAR:
case CLOSE_PAR: // Priority modifiers: store in stack
op_code = item.GetType();
ops.push_back( AM_PARAM_EVAL( op_code ) );
ops.emplace_back( op_code );
break;
case PUSHPARM:
@ -122,12 +122,12 @@ double AM_PARAM::GetValue( const D_CODE* aDcode ) const
wxFAIL_MSG( wxT( "AM_PARAM::GetValue(): NULL param aDcode" ) );
}
ops.push_back( AM_PARAM_EVAL( curr_value ) );
ops.emplace_back( curr_value );
break;
case PUSHVALUE: // a value is on the stack:
curr_value = item.GetValue();
ops.push_back( AM_PARAM_EVAL( curr_value ) );
ops.emplace_back( curr_value );
break;
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
{
corners.reserve( 3 );
corners.push_back( ROUNDED_CORNER( -size.x, -size.y - aDeltaX ) );
corners.push_back( ROUNDED_CORNER( KiROUND( size.y / slope ), 0 ) );
corners.push_back( ROUNDED_CORNER( -size.x, size.y + aDeltaX ) );
corners.emplace_back( -size.x, -size.y - aDeltaX );
corners.emplace_back( KiROUND( size.y / slope ), 0 );
corners.emplace_back( -size.x, size.y + aDeltaX );
}
}
else // vertical trapezoid
@ -413,9 +413,9 @@ void TransformTrapezoidToPolygon( SHAPE_POLY_SET& aCornerBuffer, const VECTOR2I&
if( aDeltaY > size.x )
{
corners.reserve( 3 );
corners.push_back( ROUNDED_CORNER( 0, -KiROUND( size.x / slope ) ) );
corners.push_back( ROUNDED_CORNER( size.x + aDeltaY, size.y ) );
corners.push_back( ROUNDED_CORNER( -size.x - aDeltaY, size.y ) );
corners.emplace_back( 0, -KiROUND( size.x / slope ) );
corners.emplace_back( 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() )
{
corners.reserve( 4 );
corners.push_back( ROUNDED_CORNER( -size.x + aDeltaY, -size.y - aDeltaX ) );
corners.push_back( ROUNDED_CORNER( size.x - aDeltaY, -size.y + aDeltaX ) );
corners.push_back( ROUNDED_CORNER( 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.emplace_back( size.x - aDeltaY, -size.y + aDeltaX );
corners.emplace_back( size.x + aDeltaY, size.y - aDeltaX );
corners.emplace_back( -size.x - aDeltaY, size.y + aDeltaX );
if( aDeltaY == size.x || aDeltaX == size.y )
CornerListRemoveDuplicates( corners );
@ -466,10 +466,10 @@ void TransformRoundChamferedRectToPolygon( SHAPE_POLY_SET& aCornerBuffer, const
std::vector<ROUNDED_CORNER> corners;
corners.reserve( 4 + chamferCnt );
corners.push_back( ROUNDED_CORNER( -size.x, -size.y, aCornerRadius ) );
corners.push_back( ROUNDED_CORNER( size.x, -size.y, aCornerRadius ) );
corners.push_back( ROUNDED_CORNER( size.x, size.y, aCornerRadius ) );
corners.push_back( ROUNDED_CORNER( -size.x, size.y, aCornerRadius ) );
corners.emplace_back( -size.x, -size.y, aCornerRadius );
corners.emplace_back( size.x, -size.y, aCornerRadius );
corners.emplace_back( size.x, size.y, aCornerRadius );
corners.emplace_back( -size.x, size.y, aCornerRadius );
if( aChamferCorners )
{

View File

@ -116,7 +116,7 @@ ClipperLib::Path SHAPE_LINE_CHAIN::convertToClipper( bool aRequiredOrientation,
size_t z_value_ptr = aZValueBuffer.size();
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() );

View File

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

View File

@ -103,7 +103,7 @@ public:
void AddNet( const wxString& aPinName, const wxString& aNetName, const wxString& aPinFunction,
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(); }

View File

@ -259,7 +259,7 @@ struct DATA
app.SetSpecular( 0.12f, 0.12f, 0.12f );
app.SetAmbient( 0.1f, 0.1f, 0.1f );
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();
}
@ -1167,7 +1167,7 @@ bool processFace( const TopoDS_Face& face, DATA& data, SGNODE* parent,
vshape.SetParent( parent );
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
// 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 );
if( !partID.empty() )
data.faces.insert( std::pair< std::string, SGNODE* >( id2, vshape2.GetRawPtr() ) );
data.faces.emplace( id2, vshape2.GetRawPtr() );
}
return true;

View File

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

View File

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

View File

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

View File

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