Remove RwLock around Font::characters
This commit is contained in:
parent
2fe3dd0c58
commit
93d5e222db
3 changed files with 8 additions and 14 deletions
|
@ -73,7 +73,7 @@ impl super::View for FontBook {
|
|||
let named_chars = self.named_chars.entry(text_style).or_insert_with(|| {
|
||||
ui.fonts()
|
||||
.lock()
|
||||
.font(text_style)
|
||||
.font_mut(text_style)
|
||||
.characters()
|
||||
.iter()
|
||||
.filter(|chr| !chr.is_whitespace() && !chr.is_ascii_control())
|
||||
|
|
|
@ -205,7 +205,7 @@ pub struct Font {
|
|||
text_style: TextStyle,
|
||||
fonts: Vec<Arc<FontImpl>>,
|
||||
/// Lazily calculated.
|
||||
characters: RwLock<Option<std::collections::BTreeSet<char>>>,
|
||||
characters: Option<std::collections::BTreeSet<char>>,
|
||||
replacement_glyph: (FontIndex, GlyphInfo),
|
||||
pixels_per_point: f32,
|
||||
row_height: f32,
|
||||
|
@ -218,7 +218,7 @@ impl Font {
|
|||
return Self {
|
||||
text_style,
|
||||
fonts,
|
||||
characters: RwLock::new(None),
|
||||
characters: None,
|
||||
replacement_glyph: Default::default(),
|
||||
pixels_per_point: 1.0,
|
||||
row_height: 0.0,
|
||||
|
@ -232,7 +232,7 @@ impl Font {
|
|||
let mut slf = Self {
|
||||
text_style,
|
||||
fonts,
|
||||
characters: RwLock::new(None),
|
||||
characters: None,
|
||||
replacement_glyph: Default::default(),
|
||||
pixels_per_point,
|
||||
row_height,
|
||||
|
@ -266,15 +266,14 @@ impl Font {
|
|||
}
|
||||
|
||||
/// All supported characters
|
||||
pub fn characters(&self) -> BTreeSet<char> {
|
||||
if self.characters.read().is_none() {
|
||||
pub fn characters(&mut self) -> &BTreeSet<char> {
|
||||
self.characters.get_or_insert_with(|| {
|
||||
let mut characters = BTreeSet::new();
|
||||
for font in &self.fonts {
|
||||
characters.extend(font.characters());
|
||||
}
|
||||
self.characters.write().replace(characters);
|
||||
}
|
||||
self.characters.read().clone().unwrap()
|
||||
characters
|
||||
})
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
|
@ -416,11 +416,6 @@ impl FontsImpl {
|
|||
&self.definitions
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn font(&self, text_style: TextStyle) -> &Font {
|
||||
&self.fonts[&text_style]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn font_mut(&mut self, text_style: TextStyle) -> &mut Font {
|
||||
self.fonts.get_mut(&text_style).unwrap()
|
||||
|
|
Loading…
Reference in a new issue