JakeRoggenbuck / auto-clock-speed

A utility to check stats about your CPU, and auto regulate clock speeds to help with either performance or battery life.
https://autoclockspeed.org
MIT License
37 stars 9 forks source link

Optimize read_lid_state function call #465

Closed JakeRoggenbuck closed 1 year ago

JakeRoggenbuck commented 1 year ago

image In green is just contains function calls for the file.

Here is the code for that.

fn read_lid_state(&self) -> Result<LidState, Error> {
    if !self.found_path {
        return Ok(LidState::Unapplicable);
    }

    let lid_str = fs::read_to_string(self.best_path)?;

    let state = if lid_str.contains("open") {
        LidState::Open
    } else if lid_str.contains("closed") {
        LidState::Closed
    } else {
        LidState::Unknown
    };
    Ok(state)
}

The two contains checks could probably be more optimized with another type of check.

Camerooooon commented 1 year ago

We could convert to a prim type and use a match?

JakeRoggenbuck commented 1 year ago

We could convert to a prim type and use a match?

wdym?