From 41f7354b7a1c4b84ab16a228d253ac18da4349af Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 28 Mar 2022 13:29:34 -0700 Subject: [PATCH] Handle connection vector inline Normally, you will gain by resursing a nested loop only over the pairs that are not already handled. In this case, however, you lose time because you step outside of the cache by adding the reciprocal test at each step. Instead, we process one element at a time, keeping it cached and loop over all other elements to add to the connection. This saves us about 75% of the time for larger loops (e.g. stacked power pins on a large BGA) Fixes https://gitlab.com/kicad/code/kicad/issues/10974 (cherry picked from commit 3a98eacdb91eaf15d7105c2686fab9db4af0c814) --- eeschema/connection_graph.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index ab53a8d1b5..62b58d8add 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -652,12 +652,15 @@ void CONNECTION_GRAPH::updateItemConnectivity( const SCH_SHEET_PATH& aSheet, connected_item->SetLayer( busLine ? LAYER_BUS_JUNCTION : LAYER_JUNCTION ); } - for( auto test_it = primary_it + 1; test_it != connection_vec.end(); test_it++ ) + SCH_ITEM_SET& connected_set = connected_item->ConnectedItems( aSheet ); + connected_set.reserve( connection_vec.size() ); + + for( SCH_ITEM* test_item : connection_vec ) { bool bus_connection_ok = true; - SCH_ITEM* test_item = *test_it; - wxASSERT( test_item != connected_item ); + if( test_item == connected_item ) + continue; // Set up the link between the bus entry net and the bus if( connected_item->Type() == SCH_BUS_WIRE_ENTRY_T ) @@ -685,8 +688,7 @@ void CONNECTION_GRAPH::updateItemConnectivity( const SCH_SHEET_PATH& aSheet, test_item->ConnectionPropagatesTo( connected_item ) && bus_connection_ok ) { - connected_item->AddConnectionTo( aSheet, test_item ); - test_item->AddConnectionTo( aSheet, connected_item ); + connected_set.push_back( test_item ); } }