style(pwd): simplify physical_path implementation#8409
Merged
sylvestre merged 1 commit intouutils:mainfrom Jul 29, 2025
Merged
Conversation
|
GNU testsuite comparison: |
Contributor
|
it doesn't hurt to merge it but not sure it simplifies much |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request proposes a minor stylistic simplification for the
physical_pathfunction in thepwdutility.The current implementation is perfectly correct and performant and correctly handles the platform-specific behaviors of
env::current_dir(). It correctly avoids a redundantcanonicalize()call on Unix while applying it on other platforms like Windows where it's necessary.This PR suggests a small refactor to reduce code duplication. By calling
env::current_dir()once and then using#[cfg]blocks to apply thecanonicalize()call only where needed, the function becomes slightly more DRY.Before:
After:
I want to emphasize that this is purely a stylistic suggestion intended to enhance clarity. The functionality and performance are identical, as any modern compiler will optimize both versions to the same machine code. I recognize the original implementation is a very direct and efficient way to express the logic. This alternative is simply another valid approach that some developers may find cleaner.
Thank you for considering this minor improvement. I appreciate the high quality of the existing codebase.