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/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/game_of_life/src') 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