mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Pre-hash contents of FontFaceKey
This commit is contained in:
committed by
valadaptive
parent
560346d007
commit
3385ad5bcb
@@ -405,17 +405,21 @@ impl FontDefinitions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Unique ID for looking up a single font face/file.
|
/// Unique ID for looking up a single font face/file.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub(crate) struct FontFaceKey(pub u64);
|
pub(crate) struct FontFaceKey(u64);
|
||||||
|
|
||||||
static KEY_COUNTER: AtomicU64 = AtomicU64::new(1);
|
|
||||||
|
|
||||||
impl FontFaceKey {
|
impl FontFaceKey {
|
||||||
|
const INVALID: Self = Self(0);
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self(KEY_COUNTER.fetch_add(1, Ordering::Relaxed))
|
static KEY_COUNTER: AtomicU64 = AtomicU64::new(1);
|
||||||
|
Self(crate::util::hash(
|
||||||
|
KEY_COUNTER.fetch_add(1, Ordering::Relaxed),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Safe, because we hash the value in the constructor.
|
||||||
impl nohash_hasher::IsEnabled for FontFaceKey {}
|
impl nohash_hasher::IsEnabled for FontFaceKey {}
|
||||||
|
|
||||||
/// Cached data for working with a font family (e.g. doing character lookups).
|
/// Cached data for working with a font family (e.g. doing character lookups).
|
||||||
@@ -440,7 +444,7 @@ impl CachedFamily {
|
|||||||
return Self {
|
return Self {
|
||||||
fonts,
|
fonts,
|
||||||
characters: None,
|
characters: None,
|
||||||
replacement_glyph: Default::default(),
|
replacement_glyph: (FontFaceKey::INVALID, Default::default()),
|
||||||
glyph_info_cache: Default::default(),
|
glyph_info_cache: Default::default(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -448,7 +452,7 @@ impl CachedFamily {
|
|||||||
let mut slf = Self {
|
let mut slf = Self {
|
||||||
fonts,
|
fonts,
|
||||||
characters: None,
|
characters: None,
|
||||||
replacement_glyph: Default::default(),
|
replacement_glyph: (FontFaceKey::INVALID, Default::default()),
|
||||||
glyph_info_cache: Default::default(),
|
glyph_info_cache: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -463,7 +467,7 @@ impl CachedFamily {
|
|||||||
log::warn!(
|
log::warn!(
|
||||||
"Failed to find replacement characters {PRIMARY_REPLACEMENT_CHAR:?} or {FALLBACK_REPLACEMENT_CHAR:?}. Will use empty glyph."
|
"Failed to find replacement characters {PRIMARY_REPLACEMENT_CHAR:?} or {FALLBACK_REPLACEMENT_CHAR:?}. Will use empty glyph."
|
||||||
);
|
);
|
||||||
(FontFaceKey::default(), GlyphInfo::default())
|
(FontFaceKey::INVALID, GlyphInfo::default())
|
||||||
});
|
});
|
||||||
slf.replacement_glyph = replacement_glyph;
|
slf.replacement_glyph = replacement_glyph;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user