Use rustc_hash for hashing in game_of_life

This seems to produce a 2x speedup.
This commit is contained in:
Héctor Ramón Jiménez 2020-05-02 03:31:31 +02:00
parent e7e8e76c28
commit 4fd8e47737
2 changed files with 4 additions and 3 deletions

View file

@ -8,3 +8,4 @@ publish = false
[dependencies] [dependencies]
iced = { path = "../..", features = ["canvas", "tokio", "debug"] } iced = { path = "../..", features = ["canvas", "tokio", "debug"] }
itertools = "0.9" itertools = "0.9"
rustc-hash = "1.1"

View file

@ -159,7 +159,7 @@ mod grid {
canvas::{self, Cache, Canvas, Cursor, Event, Frame, Geometry, Path}, canvas::{self, Cache, Canvas, Cursor, Event, Frame, Geometry, Path},
mouse, Color, Element, Length, Point, Rectangle, Size, Vector, mouse, Color, Element, Length, Point, Rectangle, Size, Vector,
}; };
use std::collections::{HashMap, HashSet}; use rustc_hash::{FxHashMap, FxHashSet};
pub struct Grid { pub struct Grid {
life: Life, life: Life,
@ -395,12 +395,12 @@ mod grid {
#[derive(Default)] #[derive(Default)]
pub struct Life { pub struct Life {
cells: HashSet<Cell>, cells: FxHashSet<Cell>,
} }
impl Life { impl Life {
fn tick(&mut self) { fn tick(&mut self) {
let mut adjacent_life = HashMap::new(); let mut adjacent_life = FxHashMap::default();
for cell in &self.cells { for cell in &self.cells {
let _ = adjacent_life.entry(*cell).or_insert(0); let _ = adjacent_life.entry(*cell).or_insert(0);