Optimize BOARD_ITEM::GetParentFootprint.

CPU -8% when panning a board.
This commit is contained in:
Alex Shvartzkop 2024-06-20 04:24:40 +03:00
parent ec271c20db
commit 48f6f837a1
1 changed files with 16 additions and 1 deletions

View File

@ -247,9 +247,24 @@ std::shared_ptr<SHAPE_SEGMENT> BOARD_ITEM::GetEffectiveHoleShape() const
FOOTPRINT* BOARD_ITEM::GetParentFootprint() const
{
// EDA_ITEM::IsType is too slow here.
auto isContainer = []( BOARD_ITEM_CONTAINER* aTest )
{
switch( aTest->Type() )
{
case PCB_GROUP_T:
case PCB_GENERATOR_T:
case PCB_TABLE_T:
return true;
default:
return false;
}
};
BOARD_ITEM_CONTAINER* ancestor = GetParent();
while( ancestor && ancestor->IsType( { PCB_GROUP_T, PCB_GENERATOR_T, PCB_TABLE_T } ) )
while( ancestor && isContainer( ancestor ) )
ancestor = ancestor->GetParent();
if( ancestor && ancestor->Type() == PCB_FOOTPRINT_T )