From 7abe2e3ea0ae9b33519d90840652f947d1e5b4e8 Mon Sep 17 00:00:00 2001
From: Alex Shvartzkop <dudesuchamazing@gmail.com>
Date: Tue, 7 Nov 2023 01:20:25 +0300
Subject: [PATCH] Restore clearance cache usage in PNS::NODE::NearestObstacle.

This (and the other commit) restores router performance to pre-7.0.3 levels.

(cherry-picked from commit 5e938142836990f485a64b70d85521c9dc2d80bf)
---
 pcbnew/router/pns_node.cpp | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/pcbnew/router/pns_node.cpp b/pcbnew/router/pns_node.cpp
index 67e6a94c30..d8405f2fe3 100644
--- a/pcbnew/router/pns_node.cpp
+++ b/pcbnew/router/pns_node.cpp
@@ -286,19 +286,15 @@ NODE::OPT_OBSTACLE NODE::NearestObstacle( const LINE* aLine,
     DIRECTION_45::CORNER_MODE cornerMode = ROUTER::GetInstance()->Settings().GetCornerMode();
     const int                 clearanceEpsilon = GetRuleResolver()->ClearanceEpsilon();
     OBSTACLES                 obstacleList;
-    std::vector<SEGMENT>      tmpSegs;
-
-    tmpSegs.reserve( aLine->CLine().SegmentCount() );
-
 
     for( int i = 0; i < aLine->CLine().SegmentCount(); i++ )
     {
-        // Note: Clearances between tmpSegs.back() and other items are cached,
+        // Note: Clearances between &s and other items are cached,
         // which means they'll be the same for all segments in the line.
         // Disabling the cache will lead to slowness.
 
-        tmpSegs.emplace_back( *aLine, aLine->CLine().CSegment( i ) );
-        QueryColliding( &tmpSegs.back(), obstacleList, aOpts );
+        const SEGMENT s( *aLine, aLine->CLine().CSegment( i ) );
+        QueryColliding( &s, obstacleList, aOpts );
     }
 
     if( aLine->EndsWithVia() )