Skip to content

Commit

Permalink
Allocate right-sized Vec for steps.
Browse files Browse the repository at this point in the history
We know how many elements will be in answer so use with_capcity instead
of new.
  • Loading branch information
enebo committed Jun 6, 2020
1 parent e8b3a9c commit a294e8c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bracket-pathfinding/src/astar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -187,6 +187,6 @@ impl AStar {
self.closed_list.insert(q.idx, q.f);
}

NavigationPath::new()
NavigationPath::new(0)
}
}

0 comments on commit a294e8c

Please # to comment.