From 3ca75a276d7423a070b3b4e9db32ecafd038e706 Mon Sep 17 00:00:00 2001 From: Lucy Date: Fri, 11 Oct 2024 18:28:13 -0400 Subject: [PATCH] Use `ahash::AHashMap`; pre-allocate tiles. --- Cargo.lock | 1 + crates/pathfind/Cargo.toml | 1 + crates/pathfind/src/lib.rs | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 34a238d..edb2021 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,6 +189,7 @@ dependencies = [ name = "aneri-pathfind" version = "0.1.0" dependencies = [ + "ahash 0.8.11", "bitflags 2.6.0", "meowtonin", "ordered-float", diff --git a/crates/pathfind/Cargo.toml b/crates/pathfind/Cargo.toml index 95b861e..fd8b351 100644 --- a/crates/pathfind/Cargo.toml +++ b/crates/pathfind/Cargo.toml @@ -9,6 +9,7 @@ license.workspace = true publish.workspace = true [dependencies] +ahash = "0.8" meowtonin = { workspace = true } pathfinding = "4" bitflags = "2" diff --git a/crates/pathfind/src/lib.rs b/crates/pathfind/src/lib.rs index 40828ac..44a7d20 100644 --- a/crates/pathfind/src/lib.rs +++ b/crates/pathfind/src/lib.rs @@ -1,7 +1,7 @@ +use ahash::AHashMap; use bitflags::bitflags; use ordered_float::OrderedFloat; use pathfinding::prelude::*; -use std::collections::HashMap; bitflags! { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -30,7 +30,7 @@ pub struct Tile { } pub struct GameMap { - tiles: HashMap, + tiles: AHashMap, width: i32, height: i32, } @@ -43,7 +43,7 @@ pub struct GameState { impl GameMap { pub fn new(width: i32, height: i32) -> Self { GameMap { - tiles: HashMap::new(), + tiles: AHashMap::with_capacity((width.max(0) as usize) * (height.max(0) as usize)), width, height, }