Don't resize vectors in hot loops
Fixes a slowdown caused by erasing elements from the middle of a vector
during a hot loop in SHAPE_LINE_CHAIN::Simplify(). This gets called
quite a bit when loading boards and updating lines, so it needs to be as
fast as possible
Fixes https://gitlab.com/kicad/code/kicad/issues/12115
(cherry picked from commit c9c31fcbc2
)
This commit is contained in:
parent
32551cf1ea
commit
2039a1bc8b
|
@ -1739,6 +1739,9 @@ SHAPE_LINE_CHAIN& SHAPE_LINE_CHAIN::Simplify( bool aRemoveColinear )
|
|||
|
||||
i = 0;
|
||||
|
||||
m_points.push_back( pts_unique[0] );
|
||||
m_shapes.push_back( shapes_unique[0] );
|
||||
|
||||
// stage 2: eliminate colinear segments
|
||||
for( i = 1 ; i < np - 1 ; i ++ )
|
||||
{
|
||||
|
@ -1753,22 +1756,16 @@ SHAPE_LINE_CHAIN& SHAPE_LINE_CHAIN::Simplify( bool aRemoveColinear )
|
|||
const auto distToMidpoint = SEG( p_prev, p_next ).LineDistance( midpoint );
|
||||
const auto isMidpointColinear = SEG( p_prev, p_next ).Collinear( SEG( p_prev, midpoint ) );
|
||||
|
||||
if( distToMidpoint <= 1 || isMidpointColinear )
|
||||
if( distToMidpoint > 1 && !isMidpointColinear )
|
||||
{
|
||||
pts_unique.erase( pts_unique.begin() + i );
|
||||
shapes_unique.erase( shapes_unique.begin() + i );
|
||||
i--;
|
||||
np--;
|
||||
continue;
|
||||
m_points.push_back( pts_unique[i] );
|
||||
m_shapes.push_back( shapes_unique[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( i = 0 ; i < np; i ++ )
|
||||
{
|
||||
m_points.push_back( pts_unique[i] );
|
||||
m_shapes.push_back( shapes_unique[i] );
|
||||
}
|
||||
m_points.push_back( pts_unique.back() );
|
||||
m_shapes.push_back( shapes_unique.back() );
|
||||
|
||||
assert( m_points.size() == m_shapes.size() );
|
||||
|
||||
|
|
Loading…
Reference in New Issue