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

refactor: cleanup path handling #595

Merged
merged 1 commit into from
Nov 26, 2023

Conversation

amrbashir
Copy link
Contributor

@amrbashir amrbashir commented Nov 25, 2023

I was just wandering around the codebase to get a bit familiar with it and it turned to a session of small refactors around paths handling.

This PR:

  • Avoids unnecessary string allocation when tracing paths
  • Replaces mut path & path.push() with path.join() which is nicer and more concise and the cost is the same since it was already allocating when cloning
  • Avoids unncessary cloning of paths where applicable
  • Use dunce crate to remove UNC prefix
  • Improve performance of resolving ~ by avoiding unnecessary string allocations
  • Resolve ~, $Env:USERPROFILE and $HOME consistenly between different code paths
  • Use PathBuf instead of String for paths in CLI args

I may have missed a couple of places but I think I covered 90% of path handling in the codebase

- Avoids unnecessary string allocation when tracing paths
- Replaces `mut path & path.push()` with `path.join()`
- Avoids unncessary cloning of paths where applicable
- Use `dunce` crate to remove `UNC` prefix
- Improve performance of resolving `~` by avoiding unnecessary string allocations
- Resolve `~`, `$Env:USERPROFILE` and `$HOME` consistenly between different code paths
- Use `PathBuf` instead of `String` for paths in CLI args

I may have missed a couple of places but I think I covered 90% of path handling in the codebase
@LGUG2Z
Copy link
Owner

LGUG2Z commented Nov 25, 2023

This looks amazing, I'll read through the changes (and improve my own knowledge 😅) on Monday and aim to get this merged before any additional work on the animations feature. 🤞

@@ -1106,15 +1108,48 @@ pub fn send_message(bytes: &[u8]) -> Result<()> {
Ok(stream.write_all(bytes)?)
}

fn with_komorebic_socket<F: Fn() -> Result<()>>(f: F) -> Result<()> {
Copy link
Owner

Choose a reason for hiding this comment

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

This is so clever 💡

@LGUG2Z
Copy link
Owner

LGUG2Z commented Nov 26, 2023

Looks good and the tests are passing so YOLO 🚀

@LGUG2Z LGUG2Z merged commit 2a2f2bb into LGUG2Z:master Nov 26, 2023
2 checks passed
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.

2 participants