diff options
author | 2020-05-02 03:31:31 +0200 | |
---|---|---|
committer | 2020-05-02 03:33:03 +0200 | |
commit | 4fd8e47737e82817d652d86b306400da663f7a98 (patch) | |
tree | ae92fcb39dfb52d8ce4f504a9bb6dea1a4a664af /examples/game_of_life | |
parent | e7e8e76c28e5bc8eac0c98d6d72c7e49d65468fc (diff) | |
download | iced-4fd8e47737e82817d652d86b306400da663f7a98.tar.gz iced-4fd8e47737e82817d652d86b306400da663f7a98.tar.bz2 iced-4fd8e47737e82817d652d86b306400da663f7a98.zip |
Use `rustc_hash` for hashing in `game_of_life`
This seems to produce a 2x speedup.
Diffstat (limited to 'examples/game_of_life')
-rw-r--r-- | examples/game_of_life/Cargo.toml | 1 | ||||
-rw-r--r-- | examples/game_of_life/src/main.rs | 6 |
2 files changed, 4 insertions, 3 deletions
diff --git a/examples/game_of_life/Cargo.toml b/examples/game_of_life/Cargo.toml index b1054537..2b945c4c 100644 --- a/examples/game_of_life/Cargo.toml +++ b/examples/game_of_life/Cargo.toml @@ -8,3 +8,4 @@ publish = false [dependencies] iced = { path = "../..", features = ["canvas", "tokio", "debug"] } itertools = "0.9" +rustc-hash = "1.1" diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 17b4090d..fb4b5b75 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -159,7 +159,7 @@ mod grid { canvas::{self, Cache, Canvas, Cursor, Event, Frame, Geometry, Path}, mouse, Color, Element, Length, Point, Rectangle, Size, Vector, }; - use std::collections::{HashMap, HashSet}; + use rustc_hash::{FxHashMap, FxHashSet}; pub struct Grid { life: Life, @@ -395,12 +395,12 @@ mod grid { #[derive(Default)] pub struct Life { - cells: HashSet<Cell>, + cells: FxHashSet<Cell>, } impl Life { fn tick(&mut self) { - let mut adjacent_life = HashMap::new(); + let mut adjacent_life = FxHashMap::default(); for cell in &self.cells { let _ = adjacent_life.entry(*cell).or_insert(0); |