Skip to content

Commit 62228c7

Browse files
committed
Improve access's to HashMaps
1 parent 9ed84e5 commit 62228c7

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

crates/index/src/grid.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,12 @@ impl TileGrid {
112112
}
113113

114114
fn insert_to_tile(&mut self, entity: Entity, tile_coords: IVec2) {
115-
match self.tiles.get_mut(&tile_coords) {
116-
Some(tile) => {
117-
let inserted = tile.insert(entity);
118-
debug_assert!(inserted);
119-
}
120-
None => {
121-
let mut tile = AHashSet::new();
122-
tile.insert(entity);
123-
let old = self.tiles.insert(tile_coords, tile);
124-
debug_assert!(old.is_none());
125-
}
126-
}
115+
let inserted = self
116+
.tiles
117+
.entry(tile_coords)
118+
.or_insert_with(AHashSet::new)
119+
.insert(entity);
120+
debug_assert!(inserted);
127121
}
128122

129123
fn remove_from_tile(&mut self, entity: Entity, tile_coords: IVec2) {

crates/pathing/src/exclusion.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,10 @@ impl Merger {
132132

133133
fn insert(&mut self, exclusion: ExclusionArea) {
134134
let key = self.key(&exclusion);
135-
match self.grid.get_mut(&key) {
136-
Some(exclusions) => exclusions.push(exclusion),
137-
None => {
138-
self.grid.insert(key, vec![exclusion]);
139-
}
140-
}
135+
self.grid
136+
.entry(key)
137+
.or_insert_with(Vec::new)
138+
.push(exclusion);
141139
}
142140

143141
fn remove_intersecting(&mut self, exclusion: &ExclusionArea) -> Vec<ExclusionArea> {

0 commit comments

Comments
 (0)