gpui: Use static keyword with LazyLock when loading system fonts (#34555)

Use the `static` keyword to actually make the `LazyLock` static, which
previously would reinitialize on every call to `SvgRenderer::new`.

Related: #26335 

Release Notes:

- N/A
This commit is contained in:
tidely 2025-07-18 13:35:38 +03:00 committed by GitHub
parent 00097df0d5
commit 7e3fd7bb02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -27,7 +27,7 @@ pub enum SvgSize {
impl SvgRenderer { impl SvgRenderer {
pub fn new(asset_source: Arc<dyn AssetSource>) -> Self { pub fn new(asset_source: Arc<dyn AssetSource>) -> Self {
let font_db = LazyLock::new(|| { static FONT_DB: LazyLock<Arc<usvg::fontdb::Database>> = LazyLock::new(|| {
let mut db = usvg::fontdb::Database::new(); let mut db = usvg::fontdb::Database::new();
db.load_system_fonts(); db.load_system_fonts();
Arc::new(db) Arc::new(db)
@ -36,7 +36,7 @@ impl SvgRenderer {
let font_resolver = Box::new( let font_resolver = Box::new(
move |font: &usvg::Font, db: &mut Arc<usvg::fontdb::Database>| { move |font: &usvg::Font, db: &mut Arc<usvg::fontdb::Database>| {
if db.is_empty() { if db.is_empty() {
*db = font_db.clone(); *db = FONT_DB.clone();
} }
default_font_resolver(font, db) default_font_resolver(font, db)
}, },