From 43e5266562fa495cda617ba78227c51b14d54e0e Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Tue, 12 Oct 2021 10:05:05 +0100 Subject: [PATCH] cache logo svg --- core/src/editor.rs | 4 ++-- core/src/svg.rs | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/editor.rs b/core/src/editor.rs index e70f24a8..a227427d 100644 --- a/core/src/editor.rs +++ b/core/src/editor.rs @@ -15,7 +15,7 @@ use crate::signature::SignatureState; use crate::split::LapceSplitNew; use crate::state::LapceWorkspace; -use crate::svg::{file_svg_new, get_svg}; +use crate::svg::{file_svg_new, get_svg, logo_svg}; use crate::theme::OldLapceTheme; use crate::{buffer::get_word_property, state::LapceFocus}; use crate::{buffer::matching_char, data::LapceEditorViewData}; @@ -4166,7 +4166,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { ); } LapceEditorViewContent::None => { - let svg = Svg::from_str(LOGO).unwrap(); + let svg = logo_svg(); let size = ctx.size(); let svg_size = 100.0; let rect = Size::ZERO diff --git a/core/src/svg.rs b/core/src/svg.rs index 493b1bc4..3dd65169 100644 --- a/core/src/svg.rs +++ b/core/src/svg.rs @@ -13,7 +13,7 @@ use parking_lot::Mutex; use usvg; -use crate::config::Config; +use crate::config::{Config, LOGO}; pub const ICONS_DIR: Dir = include_dir!("../icons"); lazy_static! { @@ -41,6 +41,16 @@ fn get_svg(&self, name: &str) -> Option { } } +pub fn logo_svg() -> Svg { + let name = "lapce_logo"; + let mut svgs = SVG_STORE.svgs.lock(); + if !svgs.contains_key(name) { + let svg = Svg::from_str(LOGO).ok(); + svgs.insert(name.to_string(), svg); + } + svgs.get(name).map(|s| s.clone()).unwrap().unwrap() +} + pub fn get_svg(name: &str) -> Option { SVG_STORE.get_svg(name) }