From 331d3185f3494885413db4fa01c672188361d499 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 20 Apr 2024 14:49:25 +0800 Subject: [PATCH] perf: cache each file's icon to avoid redundant calculations at rendering --- yazi-config/src/theme/filetype.rs | 4 ++-- yazi-config/src/theme/icon.rs | 9 ++++--- yazi-config/src/theme/mod.rs | 4 ---- yazi-config/src/theme/theme.rs | 4 ++-- yazi-plugin/src/elements/span.rs | 2 +- yazi-plugin/src/elements/style.rs | 6 ++--- yazi-shared/src/fs/icon.rs | 1 + yazi-shared/src/fs/mod.rs | 2 ++ yazi-shared/src/lib.rs | 1 + .../src/theme/color.rs | 0 yazi-shared/src/theme/mod.rs | 5 ++++ .../src/theme/style.rs | 24 +++++++++---------- 12 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 yazi-shared/src/fs/icon.rs rename {yazi-config => yazi-shared}/src/theme/color.rs (100%) create mode 100644 yazi-shared/src/theme/mod.rs rename {yazi-config => yazi-shared}/src/theme/style.rs (82%) diff --git a/yazi-config/src/theme/filetype.rs b/yazi-config/src/theme/filetype.rs index cac982d2..31528caf 100644 --- a/yazi-config/src/theme/filetype.rs +++ b/yazi-config/src/theme/filetype.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Deserializer}; -use yazi_shared::fs::File; +use yazi_shared::{fs::File, theme::{Color, Style, StyleShadow}}; -use super::{Color, Is, Style, StyleShadow}; +use super::Is; use crate::Pattern; pub struct Filetype { diff --git a/yazi-config/src/theme/icon.rs b/yazi-config/src/theme/icon.rs index c9b0f4db..e6530037 100644 --- a/yazi-config/src/theme/icon.rs +++ b/yazi-config/src/theme/icon.rs @@ -1,12 +1,11 @@ use serde::{Deserialize, Deserializer}; -use yazi_shared::fs::File; +use yazi_shared::{fs::File, theme::{Color, Style, StyleShadow}}; -use super::Style; -use crate::{preset::Preset, theme::{Color, Is, StyleShadow}, Pattern}; +use crate::{preset::Preset, theme::Is, Pattern}; pub struct Icon { - pub is: Is, - pub name: Pattern, + is: Is, + name: Pattern, pub text: String, pub style: Style, } diff --git a/yazi-config/src/theme/mod.rs b/yazi-config/src/theme/mod.rs index f4fd0102..28051c97 100644 --- a/yazi-config/src/theme/mod.rs +++ b/yazi-config/src/theme/mod.rs @@ -1,15 +1,11 @@ -mod color; mod filetype; mod flavor; mod icon; mod is; -mod style; mod theme; -pub use color::*; pub use filetype::*; pub use flavor::*; pub use icon::*; pub use is::*; -pub use style::*; pub use theme::*; diff --git a/yazi-config/src/theme/theme.rs b/yazi-config/src/theme/theme.rs index 6cd96ca8..00508ded 100644 --- a/yazi-config/src/theme/theme.rs +++ b/yazi-config/src/theme/theme.rs @@ -2,9 +2,9 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; use validator::Validate; -use yazi_shared::{fs::expand_path, Xdg}; +use yazi_shared::{fs::expand_path, theme::Style, Xdg}; -use super::{Filetype, Flavor, Icon, Style}; +use super::{Filetype, Flavor, Icon}; use crate::{validation::check_validation, MERGED_THEME}; #[derive(Deserialize, Serialize)] diff --git a/yazi-plugin/src/elements/span.rs b/yazi-plugin/src/elements/span.rs index f7631118..96549f3c 100644 --- a/yazi-plugin/src/elements/span.rs +++ b/yazi-plugin/src/elements/span.rs @@ -1,5 +1,5 @@ use mlua::{AnyUserData, ExternalError, FromLua, Lua, Table, UserData, UserDataMethods, Value}; -use yazi_config::theme::Color; +use yazi_shared::theme::Color; use super::Style; diff --git a/yazi-plugin/src/elements/style.rs b/yazi-plugin/src/elements/style.rs index 051419b1..67070b99 100644 --- a/yazi-plugin/src/elements/style.rs +++ b/yazi-plugin/src/elements/style.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use mlua::{AnyUserData, ExternalError, ExternalResult, Lua, Table, UserData, UserDataMethods, Value}; -use yazi_config::theme::Color; +use yazi_shared::theme::Color; #[derive(Clone, Copy, Default)] pub struct Style(pub(super) ratatui::style::Style); @@ -17,8 +17,8 @@ impl Style { } } -impl From for Style { - fn from(value: yazi_config::theme::Style) -> Self { Self(value.into()) } +impl From for Style { + fn from(value: yazi_shared::theme::Style) -> Self { Self(value.into()) } } impl<'a> TryFrom> for Style { diff --git a/yazi-shared/src/fs/icon.rs b/yazi-shared/src/fs/icon.rs new file mode 100644 index 00000000..25906715 --- /dev/null +++ b/yazi-shared/src/fs/icon.rs @@ -0,0 +1 @@ +pub struct Icon {} diff --git a/yazi-shared/src/fs/mod.rs b/yazi-shared/src/fs/mod.rs index 9cd7865e..5f076f12 100644 --- a/yazi-shared/src/fs/mod.rs +++ b/yazi-shared/src/fs/mod.rs @@ -1,6 +1,7 @@ mod cha; mod file; mod fns; +mod icon; mod op; mod path; mod url; @@ -8,6 +9,7 @@ mod url; pub use cha::*; pub use file::*; pub use fns::*; +pub use icon::*; pub use op::*; pub use path::*; pub use url::*; diff --git a/yazi-shared/src/lib.rs b/yazi-shared/src/lib.rs index 76494181..1a81d158 100644 --- a/yazi-shared/src/lib.rs +++ b/yazi-shared/src/lib.rs @@ -13,6 +13,7 @@ mod number; mod os; mod ro_cell; pub mod term; +pub mod theme; mod throttle; mod time; mod xdg; diff --git a/yazi-config/src/theme/color.rs b/yazi-shared/src/theme/color.rs similarity index 100% rename from yazi-config/src/theme/color.rs rename to yazi-shared/src/theme/color.rs diff --git a/yazi-shared/src/theme/mod.rs b/yazi-shared/src/theme/mod.rs new file mode 100644 index 00000000..b17c1de9 --- /dev/null +++ b/yazi-shared/src/theme/mod.rs @@ -0,0 +1,5 @@ +mod color; +mod style; + +pub use color::*; +pub use style::*; diff --git a/yazi-config/src/theme/style.rs b/yazi-shared/src/theme/style.rs similarity index 82% rename from yazi-config/src/theme/style.rs rename to yazi-shared/src/theme/style.rs index 39e0a069..5fe86deb 100644 --- a/yazi-config/src/theme/style.rs +++ b/yazi-shared/src/theme/style.rs @@ -37,29 +37,29 @@ impl From