From 4fd8e47737e82817d652d86b306400da663f7a98 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 2 May 2020 03:31:31 +0200 Subject: Use `rustc_hash` for hashing in `game_of_life` This seems to produce a 2x speedup. --- examples/game_of_life/Cargo.toml | 1 + examples/game_of_life/src/main.rs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'examples') 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, + cells: FxHashSet, } 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); -- cgit