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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/LGUG2Z/komorebi/pull/595
**Author:** [@amrbashir](https://github.com/amrbashir)
**Created:** 11/25/2023
**Status:** ✅ Merged
**Merged:** 11/27/2023
**Merged by:** [@LGUG2Z](https://github.com/LGUG2Z)
**Base:** `master` ← **Head:** `refactor/cleanup-paths-handling`
---
### 📝 Commits (1)
- [`3a4dcf1`](https://github.com/LGUG2Z/komorebi/commit/3a4dcf1a5243ad5e16f51e43aa35c661d1149920) refactor: cleanup path handling
### 📊 Changes
**18 files changed** (+305 additions, -530 deletions)
<details>
<summary>View changed files</summary>
📝 `Cargo.lock` (+9 -0)
📝 `Cargo.toml` (+3 -0)
📝 `komorebi-core/Cargo.toml` (+3 -1)
📝 `komorebi-core/src/custom_layout.rs` (+11 -13)
📝 `komorebi-core/src/lib.rs` (+35 -0)
📝 `komorebi/Cargo.toml` (+2 -2)
📝 `komorebi/src/main.rs` (+8 -28)
📝 `komorebi/src/monitor.rs` (+2 -3)
📝 `komorebi/src/process_command.rs` (+18 -38)
📝 `komorebi/src/process_movement.rs` (+1 -1)
📝 `komorebi/src/static_config.rs` (+4 -9)
📝 `komorebi/src/window.rs` (+4 -4)
📝 `komorebi/src/window_manager.rs` (+62 -75)
📝 `komorebi/src/windows_api.rs` (+1 -1)
📝 `komorebi/src/winevent_listener.rs` (+1 -1)
📝 `komorebi/src/workspace.rs` (+2 -2)
📝 `komorebic/Cargo.toml` (+3 -2)
📝 `komorebic/src/main.rs` (+136 -350)
</details>
### 📄 Description
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
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/LGUG2Z/komorebi/pull/595
Author: @amrbashir
Created: 11/25/2023
Status: ✅ Merged
Merged: 11/27/2023
Merged by: @LGUG2Z
Base:
master← Head:refactor/cleanup-paths-handling📝 Commits (1)
3a4dcf1refactor: cleanup path handling📊 Changes
18 files changed (+305 additions, -530 deletions)
View changed files
📝
Cargo.lock(+9 -0)📝
Cargo.toml(+3 -0)📝
komorebi-core/Cargo.toml(+3 -1)📝
komorebi-core/src/custom_layout.rs(+11 -13)📝
komorebi-core/src/lib.rs(+35 -0)📝
komorebi/Cargo.toml(+2 -2)📝
komorebi/src/main.rs(+8 -28)📝
komorebi/src/monitor.rs(+2 -3)📝
komorebi/src/process_command.rs(+18 -38)📝
komorebi/src/process_movement.rs(+1 -1)📝
komorebi/src/static_config.rs(+4 -9)📝
komorebi/src/window.rs(+4 -4)📝
komorebi/src/window_manager.rs(+62 -75)📝
komorebi/src/windows_api.rs(+1 -1)📝
komorebi/src/winevent_listener.rs(+1 -1)📝
komorebi/src/workspace.rs(+2 -2)📝
komorebic/Cargo.toml(+3 -2)📝
komorebic/src/main.rs(+136 -350)📄 Description
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:
mut path & path.push()withpath.join()which is nicer and more concise and the cost is the same since it was already allocating when cloningduncecrate to removeUNCprefix~by avoiding unnecessary string allocations~,$Env:USERPROFILEand$HOMEconsistenly between different code pathsPathBufinstead ofStringfor paths in CLI argsI may have missed a couple of places but I think I covered 90% of path handling in the codebase
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.