From 4f672f0d39c5307813d5ffe15461927768a5a412 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 11 Oct 2018 05:12:22 -0700 Subject: [PATCH] Fixing a number of dynamic_casts Dynamic casts should only be used when we explicitly check for the resulting pointer to be NULL. Where we know the class is castable we can use static_cast, save on overhead and ensure our resulting pointer is non-null. --- common/legacy_gal/block.cpp | 5 ++++- eeschema/eeschema_config.cpp | 2 +- eeschema/operations_on_items_lists.cpp | 12 ++++++------ pcbnew/router/pns_kicad_iface.cpp | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/common/legacy_gal/block.cpp b/common/legacy_gal/block.cpp index 122724f493..14714f0399 100644 --- a/common/legacy_gal/block.cpp +++ b/common/legacy_gal/block.cpp @@ -194,5 +194,8 @@ void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) aPanel->GetParent()->DisplayToolMsg( wxEmptyString ); // ugly, but temporary - dynamic_cast( aPanel )->SetDefaultCursor(); + auto gal_panel = dynamic_cast( aPanel ); + + if( gal_panel ) + gal_panel->SetDefaultCursor(); } diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index b40013260e..29497af352 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -546,7 +546,7 @@ void LIB_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg ) } } - auto painter = dynamic_cast( GetCanvas()->GetView()->GetPainter() ); + auto painter = static_cast( GetCanvas()->GetView()->GetPainter() ); KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings(); settings->m_ShowPinsElectricalType = m_showPinElectricalTypeName; diff --git a/eeschema/operations_on_items_lists.cpp b/eeschema/operations_on_items_lists.cpp index 9a4ca4710e..f117679425 100644 --- a/eeschema/operations_on_items_lists.cpp +++ b/eeschema/operations_on_items_lists.cpp @@ -76,7 +76,7 @@ void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, const wxPoint& rotationPo { for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) { - SCH_ITEM* item = dynamic_cast( aItemsList.GetPickedItem( ii ) ); + SCH_ITEM* item = static_cast( aItemsList.GetPickedItem( ii ) ); item->Rotate( rotationPoint ); // Place it in its new position. item->ClearFlags(); } @@ -87,7 +87,7 @@ void MirrorY( PICKED_ITEMS_LIST& aItemsList, const wxPoint& aMirrorPoint ) { for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) { - SCH_ITEM* item = dynamic_cast( aItemsList.GetPickedItem( ii ) ); + SCH_ITEM* item = static_cast( aItemsList.GetPickedItem( ii ) ); item->MirrorY( aMirrorPoint.x ); // Place it in its new position. item->ClearFlags(); } @@ -98,7 +98,7 @@ void MirrorX( PICKED_ITEMS_LIST& aItemsList, const wxPoint& aMirrorPoint ) { for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) { - SCH_ITEM* item = dynamic_cast( aItemsList.GetPickedItem( ii ) ); + SCH_ITEM* item = static_cast( aItemsList.GetPickedItem( ii ) ); item->MirrorX( aMirrorPoint.y ); // Place it in its new position. item->ClearFlags(); } @@ -113,7 +113,7 @@ void SCH_EDIT_FRAME::CheckListConnections( PICKED_ITEMS_LIST& aItemsList, bool a GetSchematicConnections( connections ); for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) { - SCH_ITEM* item = dynamic_cast( aItemsList.GetPickedItem( ii ) ); + SCH_ITEM* item = static_cast( aItemsList.GetPickedItem( ii ) ); std::vector< wxPoint > new_pts; if( !item->IsConnectable() ) @@ -165,7 +165,7 @@ void SCH_EDIT_FRAME::DeleteItemsInList( PICKED_ITEMS_LIST& aItemsList, bool aApp { for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) { - SCH_ITEM* item = dynamic_cast( aItemsList.GetPickedItem( ii ) ); + SCH_ITEM* item = static_cast( aItemsList.GetPickedItem( ii ) ); if( item->GetFlags() & STRUCT_DELETED ) continue; @@ -235,7 +235,7 @@ void SCH_EDIT_FRAME::DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) { - olditem = dynamic_cast( aItemsList.GetPickedItem( ii ) ); + olditem = static_cast( aItemsList.GetPickedItem( ii ) ); newitem = DuplicateStruct( olditem ); aItemsList.SetPickedItem( newitem, ii ); diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 9d7d747e2f..01b0030ff1 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -1005,7 +1005,7 @@ void PNS_KICAD_IFACE::SyncWorld( PNS::NODE *aWorld ) } else if( gitem->Type() == PCB_TEXT_T ) { - syncTextItem( aWorld, dynamic_cast( gitem ), gitem->GetLayer() ); + syncTextItem( aWorld, static_cast( gitem ), gitem->GetLayer() ); } }