Avoid re-checking items already selected

If you select a track with many segments (e.g. a length-tuned track) and
then select all connected items again ('U' -> 'U'), we would iterate
over all items in the selection and mark connections for each of the n
segments n separate times.

We avoid this by using the marked flag to show when the segment has
already been visited by the routine.  This means that if the segment has
been checked for connections because it was connected to the previous
item, it won't be checked for connections again.  However, a selection
that interleaves items from multiple connection segments will still
(potentially) be multiply checked as the BUSY flag is cleared each time
there is one not-BUSY track in the selection.
This commit is contained in:
Seth Hillbrand 2018-05-22 16:20:54 -07:00
parent b625d29151
commit 8d52dc9451
1 changed files with 7 additions and 1 deletions

View File

@ -863,11 +863,17 @@ int SELECTION_TOOL::expandSelectedConnection( const TOOL_EVENT& aEvent )
// copy the selection, since we're going to iterate and modify
auto selection = m_selection.GetItems();
// We use the BUSY flag to mark connections
for( auto item : selection )
item->SetState( BUSY, false );
for( auto item : selection )
{
TRACK* trackItem = dynamic_cast<TRACK*>( item );
if( trackItem )
// Track items marked BUSY have already been visited
// therefore their connections have already been marked
if( trackItem && !trackItem->GetState( BUSY ) )
selectAllItemsConnectedToTrack( *trackItem );
}