chore(perf): replace some string replacement and comparison with characters for performance

This commit is contained in:
2025-10-24 18:59:15 -07:00
parent 86fa00928e
commit 0b0b4dc19d
2 changed files with 6 additions and 6 deletions

View File

@@ -99,7 +99,7 @@ impl BlsEntry {
self.linux self.linux
.clone() .clone()
.or(self.efi.clone()) .or(self.efi.clone())
.map(|path| path.replace("/", "\\").trim_start_matches("\\").to_string()) .map(|path| path.replace('/', "\\").trim_start_matches('\\').to_string())
} }
/// Fetches the path to an initrd to pass to the kernel, if any. /// Fetches the path to an initrd to pass to the kernel, if any.
@@ -107,7 +107,7 @@ impl BlsEntry {
pub fn initrd_path(&self) -> Option<String> { pub fn initrd_path(&self) -> Option<String> {
self.initrd self.initrd
.clone() .clone()
.map(|path| path.replace("/", "\\").trim_start_matches("\\").to_string()) .map(|path| path.replace('/', "\\").trim_start_matches('\\').to_string())
} }
/// Fetches the options to pass to the kernel, if any. /// Fetches the options to pass to the kernel, if any.

View File

@@ -37,7 +37,7 @@ pub fn device_path_root(path: &DevicePath) -> Result<String> {
let item = item.to_string(DisplayOnly(false), AllowShortcuts(false)); let item = item.to_string(DisplayOnly(false), AllowShortcuts(false));
if item if item
.as_ref() .as_ref()
.map(|item| item.to_string().contains("(")) .map(|item| item.to_string().contains('('))
.unwrap_or(false) .unwrap_or(false)
{ {
Some(item.unwrap_or_default()) Some(item.unwrap_or_default())
@@ -62,7 +62,7 @@ pub fn device_path_subpath(path: &DevicePath) -> Result<String> {
let item = item.to_string(DisplayOnly(false), AllowShortcuts(false)); let item = item.to_string(DisplayOnly(false), AllowShortcuts(false));
if item if item
.as_ref() .as_ref()
.map(|item| item.to_string().contains("(")) .map(|item| item.to_string().contains('('))
.unwrap_or(false) .unwrap_or(false)
{ {
None None
@@ -104,11 +104,11 @@ pub fn resolve_path(default_root_path: &DevicePath, input: &str) -> Result<Resol
it.to_string(DisplayOnly(false), AllowShortcuts(false)) it.to_string(DisplayOnly(false), AllowShortcuts(false))
.unwrap_or_default() .unwrap_or_default()
}) })
.map(|it| it.to_string().contains("(")) .map(|it| it.to_string().contains('('))
.unwrap_or(false); .unwrap_or(false);
if !path_has_device { if !path_has_device {
let mut input = input.to_string(); let mut input = input.to_string();
if !input.starts_with("\\") { if !input.starts_with('\\') {
input.insert(0, '\\'); input.insert(0, '\\');
} }
input.insert_str( input.insert_str(