From 3e281d1828701a4a85036a60f7fb28c7755335da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n?= Date: Sat, 30 Mar 2024 02:17:39 +0100 Subject: [PATCH] Use `rustc-hash` for `HashSet` of `glyphs_in_use` (#90) --- Cargo.toml | 3 ++- src/text_atlas.rs | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e79ac24..d421ca9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,8 @@ license = "MIT OR Apache-2.0 OR Zlib" wgpu = { version = "0.19", default-features = false, features = ["wgsl"] } etagere = "0.2.10" cosmic-text = "0.11" -lru = "0.12.1" +lru = { version = "0.12.1", default-features = false } +rustc-hash = "1.1" [dev-dependencies] winit = { version = "0.29.10", features = ["rwh_05"] } diff --git a/src/text_atlas.rs b/src/text_atlas.rs index 44e017c..c1bc0a8 100644 --- a/src/text_atlas.rs +++ b/src/text_atlas.rs @@ -4,7 +4,11 @@ use crate::{ }; use etagere::{size2, Allocation, BucketedAtlasAllocator}; use lru::LruCache; -use std::{borrow::Cow, collections::HashSet, mem::size_of, num::NonZeroU64, sync::Arc}; +use rustc_hash::FxHasher; +use std::{ + borrow::Cow, collections::HashSet, hash::BuildHasherDefault, mem::size_of, num::NonZeroU64, + sync::Arc, +}; use wgpu::{ BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutEntry, BindingResource, BindingType, BlendState, BufferBindingType, ColorTargetState, ColorWrites, @@ -17,6 +21,8 @@ use wgpu::{ VertexState, }; +type Hasher = BuildHasherDefault; + #[allow(dead_code)] pub(crate) struct InnerAtlas { pub kind: Kind, @@ -24,8 +30,8 @@ pub(crate) struct InnerAtlas { pub texture_view: TextureView, pub packer: BucketedAtlasAllocator, pub size: u32, - pub glyph_cache: LruCache, - pub glyphs_in_use: HashSet, + pub glyph_cache: LruCache, + pub glyphs_in_use: HashSet, pub max_texture_dimension_2d: u32, } @@ -56,8 +62,8 @@ impl InnerAtlas { let texture_view = texture.create_view(&TextureViewDescriptor::default()); - let glyph_cache = LruCache::unbounded(); - let glyphs_in_use = HashSet::new(); + let glyph_cache = LruCache::unbounded_with_hasher(Hasher::default()); + let glyphs_in_use = HashSet::with_hasher(Hasher::default()); Self { kind,