Use rustc-hash for HashSet of glyphs_in_use (#90)

This commit is contained in:
Héctor Ramón 2024-03-30 02:17:39 +01:00 committed by GitHub
parent 4f24305ac5
commit 3e281d1828
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 6 deletions

View file

@ -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"] }

View file

@ -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<FxHasher>;
#[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<CacheKey, GlyphDetails>,
pub glyphs_in_use: HashSet<CacheKey>,
pub glyph_cache: LruCache<CacheKey, GlyphDetails, Hasher>,
pub glyphs_in_use: HashSet<CacheKey, Hasher>,
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,