perf: reduce memory allocations
This also changes `widget::column::with_children` and `widget::row::with_children` to take an `impl IntoIterator` instead of a `Vec`, like the `iced` variants of these functions do. This shouldn't be a breaking change since passing in a `Vec` will still compile and function exactly as before. (Using `iced::widget::Column::from_vec` or `iced::widget::Row::from_vec` isn't possible, since the elements of the `Vec` aren't checked, so the size of the resulting `Column` or `Row` won't adapt to the size of its children. Perhaps a new function could be added to mirror `iced`'s?)
This commit is contained in:
parent
840ef21e4d
commit
bd438a8581
20 changed files with 83 additions and 88 deletions
|
|
@ -148,7 +148,7 @@ impl Theme {
|
|||
#[cold]
|
||||
pub fn write_gtk4(&self) -> Result<(), OutputError> {
|
||||
let css_str = self.as_gtk4();
|
||||
let Some(config_dir) = dirs::config_dir() else {
|
||||
let Some(mut config_dir) = dirs::config_dir() else {
|
||||
return Err(OutputError::MissingConfigDir);
|
||||
};
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ impl Theme {
|
|||
"light.css"
|
||||
};
|
||||
|
||||
let config_dir = config_dir.join("gtk-4.0").join("cosmic");
|
||||
config_dir.extend(["gtk-4.0", "cosmic"]);
|
||||
if !config_dir.exists() {
|
||||
std::fs::create_dir_all(&config_dir).map_err(OutputError::Io)?;
|
||||
}
|
||||
|
|
@ -181,23 +181,20 @@ impl Theme {
|
|||
return Err(OutputError::MissingConfigDir);
|
||||
};
|
||||
|
||||
let gtk4 = config_dir.join("gtk-4.0");
|
||||
let gtk3 = config_dir.join("gtk-3.0");
|
||||
let mut gtk4 = config_dir.join("gtk-4.0");
|
||||
let mut gtk3 = config_dir.join("gtk-3.0");
|
||||
|
||||
fs::create_dir_all(>k4).map_err(OutputError::Io)?;
|
||||
fs::create_dir_all(>k3).map_err(OutputError::Io)?;
|
||||
|
||||
let cosmic_css_dir = gtk4.join("cosmic");
|
||||
let cosmic_css =
|
||||
cosmic_css_dir
|
||||
.clone()
|
||||
.join(if is_dark { "dark.css" } else { "light.css" });
|
||||
let cosmic_css = cosmic_css_dir.join(if is_dark { "dark.css" } else { "light.css" });
|
||||
|
||||
let gtk4_dest = gtk4.join("gtk.css");
|
||||
let gtk3_dest = gtk3.join("gtk.css");
|
||||
gtk4.push("gtk.css");
|
||||
gtk3.push("gtk.css");
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
for gtk_dest in [>k4_dest, >k3_dest] {
|
||||
for gtk_dest in [>k4, >k3] {
|
||||
use std::os::unix::fs::symlink;
|
||||
Self::backup_non_cosmic_css(gtk_dest, &cosmic_css_dir).map_err(OutputError::Io)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -269,8 +269,9 @@ impl Theme {
|
|||
#[cold]
|
||||
pub fn apply_vs_code(self) -> Result<(), OutputError> {
|
||||
let vs_theme = VsTheme::from(self);
|
||||
let config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?;
|
||||
let vs_code_dir = config_dir.join("Code").join("User");
|
||||
let mut config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?;
|
||||
config_dir.extend(["Code", "User"]);
|
||||
let vs_code_dir = config_dir;
|
||||
if !vs_code_dir.exists() {
|
||||
std::fs::create_dir_all(&vs_code_dir).map_err(OutputError::Io)?;
|
||||
}
|
||||
|
|
@ -292,9 +293,9 @@ impl Theme {
|
|||
|
||||
#[cold]
|
||||
pub fn reset_vs_code() -> Result<(), OutputError> {
|
||||
let config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?;
|
||||
let vs_code_dir = config_dir.join("Code").join("User");
|
||||
let settings_file = vs_code_dir.join("settings.json");
|
||||
let mut config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?;
|
||||
config_dir.extend(["Code", "User", "settings.json"]);
|
||||
let settings_file = config_dir;
|
||||
// just remove the json entry for workbench.colorCustomizations
|
||||
let settings = std::fs::read_to_string(&settings_file).unwrap_or_default();
|
||||
let mut settings: serde_json::Value = serde_json::from_str(&settings).unwrap_or_default();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue