UPSTREAM PR #2458: fix(tree): std::path::Component has infallible conversion to &[u8]#28
UPSTREAM PR #2458: fix(tree): std::path::Component has infallible conversion to &[u8]#28loci-dev wants to merge 2 commits into
std::path::Component has infallible conversion to &[u8]#28Conversation
Instead of relying on a fallible path and using a default value, we can convert directly between a `Component` and a `&[u8]`.
OverviewAnalysis of 31,034 functions (1,742 modified, 4,771 new, 4,774 removed) across two binaries shows negligible performance impact from path conversion simplification commits. Binaries analyzed:
Commits: Two focused changes simplified Function AnalysisMost performance variations are compiler-driven code generation differences rather than algorithmic changes from the source modifications: Performance-critical improvements:
Performance-critical regressions:
Non-critical changes:
Other analyzed functions showed negligible changes or compiler optimization variations in external dependencies. Source code relationship: The path conversion changes in 🔎 Full breakdown: Loci Inspector |
2c4a72b to
167bdd1
Compare
9b41e5f to
1f13824
Compare
06bc48e to
0e47b1e
Compare
8b02847 to
1bf0519
Compare
cdbe120 to
78a7ab5
Compare
49231d8 to
bc0a777
Compare
e902b63 to
c6739bc
Compare
Note
Source pull request: GitoxideLabs/gitoxide#2458
The checks/conversions done in the
_by_pathmethods inTreeandTreeRefIterare unnecessary, so this PR removes them in favor of usingOsStr::as_encoded_bytes().Since
as_os_str().as_encoded_bytes()takes&selfand (as far as I know) no platforms use internal mutability onOsStr, the underlying value must already have the form we want. The only thing thatos_str_into_bstrdoes for us is validate that the byte string contains valid UTF-8. However, the only thing theseBStrs are used for is comparison to otherBStrs. Whether either of them is valid UTF-8 does not impact the function in any way (as string conversion errors are silently ignored), so we can simply skip the whole validation step and get ever-so-slightly-cheaper lookups by path.Please let me know if this change is useful/welcome or not, I can imagine that there may be some case I have not thought of that breaks from this change.