fix(font): explicitly drop read guard in on font family lookup
This commit is contained in:
parent
ae830ca21d
commit
031818c6b0
1 changed files with 13 additions and 13 deletions
|
|
@ -16,9 +16,6 @@ pub const ID: &str = "com.system76.CosmicTk";
|
||||||
const MONO_FAMILY_DEFAULT: &str = "Noto Sans Mono";
|
const MONO_FAMILY_DEFAULT: &str = "Noto Sans Mono";
|
||||||
const SANS_FAMILY_DEFAULT: &str = "Open Sans";
|
const SANS_FAMILY_DEFAULT: &str = "Open Sans";
|
||||||
|
|
||||||
/// Stores static strings of the family names for `iced::Font` compatibility.
|
|
||||||
pub static FAMILY_MAP: LazyLock<RwLock<BTreeSet<&'static str>>> = LazyLock::new(RwLock::default);
|
|
||||||
|
|
||||||
pub static COSMIC_TK: LazyLock<RwLock<CosmicTk>> = LazyLock::new(|| {
|
pub static COSMIC_TK: LazyLock<RwLock<CosmicTk>> = LazyLock::new(|| {
|
||||||
RwLock::new(
|
RwLock::new(
|
||||||
CosmicTk::config()
|
CosmicTk::config()
|
||||||
|
|
@ -156,16 +153,19 @@ pub struct FontConfig {
|
||||||
|
|
||||||
impl From<FontConfig> for iced::Font {
|
impl From<FontConfig> for iced::Font {
|
||||||
fn from(font: FontConfig) -> Self {
|
fn from(font: FontConfig) -> Self {
|
||||||
let name = FAMILY_MAP
|
/// Stores static strings of the family names for `iced::Font` compatibility.
|
||||||
.read()
|
static FAMILY_MAP: LazyLock<RwLock<BTreeSet<&'static str>>> =
|
||||||
.unwrap()
|
LazyLock::new(RwLock::default);
|
||||||
.get(font.family.as_str())
|
|
||||||
.copied()
|
let read_guard = FAMILY_MAP.read().unwrap();
|
||||||
.unwrap_or_else(|| {
|
let name: Option<&'static str> = read_guard.get(font.family.as_str()).copied();
|
||||||
let value: &'static str = font.family.clone().leak();
|
drop(read_guard);
|
||||||
FAMILY_MAP.write().unwrap().insert(value);
|
|
||||||
value
|
let name = name.unwrap_or_else(|| {
|
||||||
});
|
let value: &'static str = font.family.clone().leak();
|
||||||
|
FAMILY_MAP.write().unwrap().insert(value);
|
||||||
|
value
|
||||||
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
family: iced::font::Family::Name(name),
|
family: iced::font::Family::Name(name),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue