aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/pathfinder/mod.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-10-04 20:35:01 -0500
committermat <git@matdoes.dev>2023-10-04 20:35:01 -0500
commit9db542f342c40478af230fd65b0bcf8cc069b5be (patch)
tree5451f1eb48d31151edb89519a160909ae1ee74bb /azalea/src/pathfinder/mod.rs
parent17734cdcbf8ea30ded09a0b14372d92c11d1cc8c (diff)
downloadazalea-drasl-9db542f342c40478af230fd65b0bcf8cc069b5be.tar.xz
preallocate edges vec in pathfinder
Diffstat (limited to 'azalea/src/pathfinder/mod.rs')
-rw-r--r--azalea/src/pathfinder/mod.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index c71d0b42..c4c4c688 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -179,7 +179,11 @@ fn goto_listener(
debug!("start: {start:?}");
let ctx = PathfinderCtx::new(world_lock);
- let successors = |pos: BlockPos| successors_fn(&ctx, pos);
+ let successors = |pos: BlockPos| {
+ let mut edges = Vec::with_capacity(16);
+ successors_fn(&mut edges, &ctx, pos);
+ edges
+ };
let mut attempt_number = 0;
@@ -281,9 +285,13 @@ fn path_found_listener(
let world_lock = instance_container.get(instance_name).expect(
"Entity tried to pathfind but the entity isn't in a valid world",
);
- let ctx = PathfinderCtx::new(world_lock);
let successors_fn: moves::SuccessorsFn = event.successors_fn;
- let successors = |pos: BlockPos| successors_fn(&ctx, pos);
+ let ctx = PathfinderCtx::new(world_lock);
+ let successors = |pos: BlockPos| {
+ let mut edges = Vec::with_capacity(16);
+ successors_fn(&mut edges, &ctx, pos);
+ edges
+ };
if successors(last_node.target)
.iter()
@@ -444,7 +452,11 @@ fn tick_execute_path(
{
// obstruction check (the path we're executing isn't possible anymore)
let ctx = PathfinderCtx::new(world_lock);
- let successors = |pos: BlockPos| successors_fn(&ctx, pos);
+ let successors = |pos: BlockPos| {
+ let mut edges = Vec::with_capacity(16);
+ successors_fn(&mut edges, &ctx, pos);
+ edges
+ };
if let Some(last_reached_node) = pathfinder.last_reached_node {
if let Some(obstructed_index) =