Clean up some auto usage

Don't make new copies of shared_ptr if we can use references.  Keep auto
usage down to hard-to-type-out sequences
This commit is contained in:
Seth Hillbrand 2022-08-15 10:47:23 -07:00
parent db91bcbabf
commit 35ac39844f
19 changed files with 34 additions and 36 deletions

View File

@ -174,7 +174,7 @@ int LIB_ID::HasIllegalChars( const UTF8& aLibItemName )
{
int offset = 0;
for( auto ch : aLibItemName )
for( auto& ch : aLibItemName )
{
if( !isLegalChar( ch ) )
return offset;

View File

@ -62,7 +62,7 @@ wxString formatWildcardExt( const wxString& aWildcard )
wxString wc;
#if defined( __WXGTK__ )
for( auto ch : aWildcard )
for( auto& ch : aWildcard )
{
if( wxIsalpha( ch ) )
wc += wxString::Format( "[%c%c]", wxTolower( ch ), wxToupper( ch ) );

View File

@ -244,7 +244,7 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet )
aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() );
aSheet->GetScreen()->SetFileExists( true );
for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
for( SCH_ITEM* aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
{
wxCHECK2( aItem->Type() == SCH_SHEET_T, continue );
auto sheet = static_cast<SCH_SHEET*>( aItem );
@ -1466,7 +1466,7 @@ void SCH_LEGACY_PLUGIN::Format( SCH_SHEET* aSheet )
auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b ) { return *a < *b; };
std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
for( auto item : screen->Items() )
for( SCH_ITEM* item : screen->Items() )
save_map.insert( item );

View File

@ -73,9 +73,7 @@ NGSPICE::NGSPICE() :
}
NGSPICE::~NGSPICE()
{
}
NGSPICE::~NGSPICE() = default;
void NGSPICE::Init( const SPICE_SIMULATOR_SETTINGS* aSettings )
@ -595,7 +593,7 @@ bool NGSPICE::loadSpinit( const string& aFileName )
if( !file.Open( aFileName ) )
return false;
for( auto cmd = file.GetFirstLine(); !file.Eof(); cmd = file.GetNextLine() )
for( wxString& cmd = file.GetFirstLine(); !file.Eof(); cmd = file.GetNextLine() )
Command( cmd.ToStdString() );
return true;

View File

@ -1209,7 +1209,7 @@ bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer( std::shared_ptr<SYMBOL_BUFF
aSymbolBuf->SetOriginal( new LIB_SYMBOL( *libSymbol ) );
// Save the derived symbols.
for( auto entry : derivedSymbols )
for( const wxString& entry : derivedSymbols )
{
std::shared_ptr<SYMBOL_BUFFER> symbol = GetBuffer( entry );
@ -1241,7 +1241,7 @@ bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer( std::shared_ptr<SYMBOL_BUFF
std::shared_ptr<SYMBOL_LIBRARY_MANAGER::SYMBOL_BUFFER>
SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffer( const wxString& aAlias ) const
{
for( auto entry : m_symbols )
for( std::shared_ptr<SYMBOL_LIBRARY_MANAGER::SYMBOL_BUFFER> entry : m_symbols )
{
if( entry->GetSymbol()->GetName() == aAlias )
return entry;
@ -1253,7 +1253,7 @@ SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffer( const wxString& aAlias ) const
bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::HasDerivedSymbols( const wxString& aParentName ) const
{
for( auto entry : m_symbols )
for( auto& entry : m_symbols )
{
if( entry->GetSymbol()->IsAlias() )
{
@ -1288,7 +1288,7 @@ size_t SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetDerivedSymbolNames( const wxString
{
wxCHECK( !aSymbolName.IsEmpty(), 0 );
for( auto entry : m_symbols )
for( auto& entry : m_symbols )
{
if( entry->GetSymbol()->IsAlias() )
{

View File

@ -584,7 +584,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
// Update our cache of the connected items.
// First, re-attach our drag labels to the original line being re-merged.
for( auto possibleLabel : m_lineConnectionCache[bendLine] )
for( EDA_ITEM* possibleLabel : m_lineConnectionCache[bendLine] )
{
switch( possibleLabel->Type() )
{
@ -684,7 +684,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
// Update our cache of the connected items.
// First, attach our drag labels to the line left behind.
for( auto possibleLabel : m_lineConnectionCache[line] )
for( EDA_ITEM* possibleLabel : m_lineConnectionCache[line] )
{
switch( possibleLabel->Type() )
{
@ -1588,7 +1588,7 @@ void SCH_MOVE_TOOL::setTransitions()
void SCH_MOVE_TOOL::commitDragLines()
{
for( auto newLine : m_newDragLines )
for( SCH_LINE* newLine : m_newDragLines )
{
newLine->ClearEditFlags();
saveCopyInUndoList( newLine, UNDO_REDO::NEWITEM, true );
@ -1596,7 +1596,7 @@ void SCH_MOVE_TOOL::commitDragLines()
// These lines have been changed, but aren't selected. We need
// to manually clear these edit flags or they'll stick around.
for( auto oldLine : m_changedDragLines )
for( SCH_LINE* oldLine : m_changedDragLines )
{
oldLine->ClearEditFlags();
}

View File

@ -102,7 +102,7 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName )
// (maybe convert geometry into positives?)
}
for( auto item : gerber->GetItems() )
for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
GetCanvas()->GetView()->Add( (KIGFX::VIEW_ITEM*) item );
}

View File

@ -824,11 +824,11 @@ const std::vector<BOARD_CONNECTED_ITEM*> CONNECTIVITY_DATA::GetConnectedItemsAtA
std::vector<BOARD_CONNECTED_ITEM*> rv;
SEG::ecoord maxErrorSq = (SEG::ecoord) aMaxError * aMaxError;
for( auto cnItem : entry.GetItems() )
for( CN_ITEM* cnItem : entry.GetItems() )
{
for( auto connected : cnItem->ConnectedItems() )
for( CN_ITEM* connected : cnItem->ConnectedItems() )
{
for( auto anchor : connected->Anchors() )
for( std::shared_ptr<CN_ANCHOR>& anchor : connected->Anchors() )
{
if( ( anchor->Pos() - aAnchor ).SquaredEuclideanNorm() <= maxErrorSq )
{
@ -995,7 +995,7 @@ const std::vector<CN_EDGE> CONNECTIVITY_DATA::GetRatsnestForComponent( FOOTPRINT
std::set<const PAD*> pads;
std::vector<CN_EDGE> edges;
for( auto pad : aComponent->Pads() )
for( PAD* pad : aComponent->Pads() )
{
nets.insert( pad->GetNetCode() );
pads.insert( pad );

View File

@ -387,7 +387,7 @@ bool CN_CLUSTER::Contains( const BOARD_CONNECTED_ITEM* aItem )
void CN_CLUSTER::Dump()
{
for( auto item : m_items )
for( CN_ITEM* item : m_items )
{
wxLogTrace( wxT( "CN" ), wxT( " - item : %p bitem : %p type : %d inet %s\n" ),
item,

View File

@ -433,7 +433,7 @@ public:
void ClearDirtyFlags()
{
for( auto item : m_items )
for( CN_ITEM* item : m_items )
item->SetDirty( false );
SetDirty( false );

View File

@ -59,7 +59,7 @@ enum PATH_STATUS {
static bool isVertexVisited( CN_ITEM* v, const std::vector<CN_ITEM*>& path )
{
for( auto u : path )
for( CN_ITEM* u : path )
{
if ( u == v )
return true;
@ -95,11 +95,11 @@ static PATH_STATUS uniquePathBetweenNodes( CN_ITEM* u, CN_ITEM* v, std::vector<C
pathFound = true;
}
for( auto ci : last->ConnectedItems() )
for( CN_ITEM* ci : last->ConnectedItems() )
{
bool vertexVisited = isVertexVisited( ci, path );
for( auto& p : Q )
for( std::vector<CN_ITEM*>& p : Q )
if( isVertexVisited( ci, p ) )
{
vertexVisited = true;

View File

@ -725,7 +725,7 @@ LSEQ PANEL_SETUP_LAYERS::getNonRemovableLayers()
PCB_LAYER_COLLECTOR collector;
LSEQ newLayerSeq = newLayers.Seq();
for( auto layer_id : curLayers.Seq() )
for( PCB_LAYER_ID layer_id : curLayers.Seq() )
{
if( IsCopperLayer( layer_id ) ) // Copper layers are not taken into account here
continue;

View File

@ -1723,7 +1723,7 @@ bool DRC_ENGINE::IsNetTie( BOARD_ITEM* aItem )
DRC_TEST_PROVIDER* DRC_ENGINE::GetTestProvider( const wxString& name ) const
{
for( auto prov : m_testProviders )
for( DRC_TEST_PROVIDER* prov : m_testProviders )
{
if( name == prov->GetName() )
return prov;

View File

@ -391,10 +391,10 @@ FOOTPRINT* FOOTPRINT_EDIT_FRAME::SelectFootprintFromBoard( BOARD* aPcb )
oldName = fpname;
for( auto mod : aPcb->Footprints() )
for( FOOTPRINT* fp : aPcb->Footprints() )
{
if( fpname == mod->GetReference() )
return mod;
if( fpname == fp->GetReference() )
return fp;
}
return nullptr;

View File

@ -359,7 +359,7 @@ FOOTPRINT* MICROWAVE_TOOL::createMicrowaveInductor( MICROWAVE_INDUCTOR_PATTERN&
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
auto pt = aInductorPattern.m_End - aInductorPattern.m_Start;
wxPoint pt = aInductorPattern.m_End - aInductorPattern.m_Start;
int min_len = KiROUND( EuclideanNorm( pt ) );
aInductorPattern.m_Length = min_len;

View File

@ -129,7 +129,7 @@ void PCB_GROUP::SetPosition( const VECTOR2I& aNewpos )
void PCB_GROUP::SetLayerRecursive( PCB_LAYER_ID aLayer, int aDepth )
{
for( auto item : m_items )
for( BOARD_ITEM* item : m_items )
{
if( ( item->Type() == PCB_GROUP_T ) && ( aDepth > 0 ) )
{

View File

@ -128,7 +128,7 @@ bool FABMASTER::Read( const std::string& aFile )
bool quoted = false;
for( auto ch : buffer )
for( auto& ch : buffer )
{
switch( ch )
{

View File

@ -133,7 +133,7 @@ VECTOR2I PCB_GRID_HELPER::AlignToArc( const VECTOR2I& aPoint, const SHAPE_ARC& a
int min_d = std::numeric_limits<int>::max();
for( auto pt : { aArc.GetP0(), aArc.GetP1() } )
for( VECTOR2I& pt : { aArc.GetP0(), aArc.GetP1() } )
{
int d = ( pt - aPoint ).EuclideanNorm();

View File

@ -661,7 +661,7 @@ bool TRACKS_CLEANER::mergeCollinearSegments( PCB_TRACK* aSeg1, PCB_TRACK* aSeg2
// If the existing connected points are not the same as the points generated by our
// min/max alg, then assign the missing points to the end closest. This ensures that
// our replacement track is still connected
for( auto pt : pts )
for( auto& pt : pts )
{
if( !dummy_seg.IsPointOnEnds( wxPoint( pt.x, pt.y ) ) )
{