From d0cc9e4fb3ca75078fcb20dd133bbdafe10ab255 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 16 May 2025 05:10:01 +0300 Subject: [PATCH] cpu: reduce allocations for EPP values --- src/cpu.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cpu.rs b/src/cpu.rs index d9f53dd..eeb4dfa 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -15,6 +15,17 @@ const VALID_EPB_STRINGS: &[&str] = &[ "power", ]; +// EPP (Energy Performance Preference) string values +const EPP_FALLBACK_VALUES: &[&str] = &[ + "default", + "performance", + "balance-performance", + "balance_performance", // alternative form with underscore + "balance-power", + "balance_power", // alternative form with underscore + "power", +]; + // Write a value to a sysfs file fn write_sysfs_value(path: impl AsRef, value: &str) -> Result<()> { let p = path.as_ref(); @@ -288,17 +299,9 @@ fn get_available_epp_values() -> Result> { if !Path::new(path).exists() { // If the file doesn't exist, fall back to a default set of common values - // This is safer than failing outright, as some systems may allow these values + // This is safer than failing outright, as some systems may allow these values │ // even without explicitly listing them - return Ok(vec![ - "default".to_string(), - "performance".to_string(), - "balance_performance".to_string(), - "balance_performance".replace('_', "-"), - "balance_power".to_string(), - "balance_power".replace('_', "-"), - "power".to_string(), - ]); + return Ok(EPP_FALLBACK_VALUES.iter().map(|&s| s.to_string()).collect()); } let content = fs::read_to_string(path).map_err(|e| {