Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize read lid state function #545

Merged

Conversation

Camerooooon
Copy link
Collaborator

Reduced two contains checks into a single split_whitespace() call with a match statement. Fixes #465

LidState::Unknown
};
Ok(state)
Ok(match lid_str.split_whitespace().last().unwrap() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the unwrap crash acs if the lid file wasn't in the right file or doesn't exist?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a safe assumption that it's in the correct format

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait actually, could you do unwrap or error and set state = LidState::Unknown if it doesn't unwrap correctly otherwise return the state

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not crash. The if statement before prevents the crash.

        if !self.found_path {
            return Ok(LidState::Unapplicable);
        }

Copy link
Owner

@JakeRoggenbuck JakeRoggenbuck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@JakeRoggenbuck
Copy link
Owner

Perfect PR. Works, Fixes issue, stays in scope, best solution. A+ work

@JakeRoggenbuck JakeRoggenbuck merged commit a1df0a1 into JakeRoggenbuck:main Jul 1, 2023
5 checks passed
@JakeRoggenbuck
Copy link
Owner

Tested
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize read_lid_state function call
2 participants