From a294e8c6bf8b2afa8b48a2c94e2ab097c7574dec Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Sat, 6 Jun 2020 09:39:34 -0500 Subject: [PATCH] Allocate right-sized Vec for steps. We know how many elements will be in answer so use with_capcity instead of new. --- bracket-pathfinding/src/astar.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bracket-pathfinding/src/astar.rs b/bracket-pathfinding/src/astar.rs index ab507f78..110c9b0c 100644 --- a/bracket-pathfinding/src/astar.rs +++ b/bracket-pathfinding/src/astar.rs @@ -60,11 +60,11 @@ impl PartialOrd for Node { impl NavigationPath { /// Makes a new (empty) NavigationPath - pub fn new() -> NavigationPath { + pub fn new(capacity: usize) -> NavigationPath { NavigationPath { destination: 0, success: false, - steps: Vec::new(), + steps: Vec::with_capacity(capacity), } } } @@ -148,7 +148,7 @@ impl AStar { /// Helper function to unwrap a path once we've found the end-point. fn found_it(&self) -> NavigationPath { - let mut result = NavigationPath::new(); + let mut result = NavigationPath::new(self.parents.len()); result.success = true; result.destination = self.end; @@ -187,6 +187,6 @@ impl AStar { self.closed_list.insert(q.idx, q.f); } - NavigationPath::new() + NavigationPath::new(0) } }