From aacc35e4afedd52e5b0bfa581426fa5ce38a78ea Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 8 Nov 2022 17:00:15 +1300 Subject: [PATCH] Use FxHasher in color to palette --- src/reduction/color.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/reduction/color.rs b/src/reduction/color.rs index 078b01c7..5284c94e 100644 --- a/src/reduction/color.rs +++ b/src/reduction/color.rs @@ -4,7 +4,10 @@ use crate::png::PngImage; use indexmap::IndexMap; use itertools::Itertools; use rgb::{FromSlice, RGB8, RGBA8}; -use std::hash::Hash; +use rustc_hash::FxHasher; +use std::hash::{BuildHasherDefault, Hash}; + +type FxIndexMap = IndexMap>; #[must_use] pub fn reduce_rgba_to_grayscale_alpha(png: &PngImage) -> Option { @@ -78,7 +81,7 @@ pub fn reduce_rgba_to_grayscale_alpha(png: &PngImage) -> Option { fn reduce_scanline_to_palette( iter: impl IntoIterator, - palette: &mut IndexMap, + palette: &mut FxIndexMap, reduced: &mut Vec, ) -> bool where @@ -107,7 +110,8 @@ pub fn reduced_color_to_palette(png: &PngImage) -> Option { return None; } let mut raw_data = Vec::with_capacity(png.data.len()); - let mut palette = IndexMap::with_capacity(257); + let mut palette = FxIndexMap::default(); + palette.reserve(257); let transparency_pixel = png .transparency_pixel .as_ref()