diff --git a/src/cache.rs b/src/cache.rs index f348b07..8e38de4 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -1,24 +1,32 @@ use once_cell::sync::Lazy; use std::collections::BTreeMap; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::sync::Mutex; pub(crate) static CACHE: Lazy = Lazy::new(Cache::default); +type IconMap = BTreeMap<(String, u16, u16), PathBuf>; +type ThemeMap = BTreeMap; #[derive(Default)] -pub(crate) struct Cache(Mutex>>); +pub(crate) struct Cache(Mutex); impl Cache { - pub fn insert(&self, theme: &str, size: u16, scale: u16, icon_name: &str, icon_path: &PathBuf) { + pub fn insert(&self, theme: &str, size: u16, scale: u16, icon_name: &str, icon_path: &Path) { let mut theme_map = self.0.lock().unwrap(); match theme_map.get_mut(theme) { Some(icon_map) => { - icon_map.insert((icon_name.to_string(), size, scale), icon_path.clone()); + icon_map.insert( + (icon_name.to_string(), size, scale), + icon_path.to_path_buf(), + ); } None => { let mut icon_map = BTreeMap::new(); - icon_map.insert((icon_name.to_string(), size, scale), icon_path.clone()); + icon_map.insert( + (icon_name.to_string(), size, scale), + icon_path.to_path_buf(), + ); theme_map.insert(theme.to_string(), icon_map); } } diff --git a/src/theme/parse.rs b/src/theme/parse.rs index 071e52c..63d0d8c 100644 --- a/src/theme/parse.rs +++ b/src/theme/parse.rs @@ -19,7 +19,7 @@ impl Theme { self.get_icon_theme_section() .and_then(|props| props.get("ScaledDirectories")) .map(|dirs| dirs.split(',').collect()) - .unwrap_or(vec![]) + .unwrap_or_default() } fn get_icon_theme_section(&self) -> Option<&Properties> { @@ -30,7 +30,7 @@ impl Theme { self.get_icon_theme_section() .and_then(|props| props.get("Inherits")) .map(|parents| parents.split(',').collect()) - .unwrap_or(vec![]) + .unwrap_or_default() } fn directories(&self) -> Vec<&str> { @@ -38,7 +38,7 @@ impl Theme { .section(Some("Icon Theme")) .and_then(|props| props.get("Directories")) .map(|dirs| dirs.split(',').collect()) - .unwrap_or(vec![]) + .unwrap_or_default() } fn get_directory<'a>(&'a self, name: &'a str) -> Option {