-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Improve performance of pathlib.Path.[is_]absolute()
#103548
Labels
3.12
bugs and security fixes
performance
Performance or resource usage
topic-pathlib
type-feature
A feature request or enhancement
Comments
barneygale
added a commit
to barneygale/cpython
that referenced
this issue
Apr 14, 2023
Pass the *unnormalized* path to `os.path.isabs()`. When making an empty path absolute, avoid calling `os.path.join()`, and prevent pathlib from later re-normalizing the result of `os.getcwd()` by storing it as `path._str`.
barneygale
added a commit
to barneygale/cpython
that referenced
this issue
Apr 29, 2023
barneygale
added a commit
to barneygale/cpython
that referenced
this issue
May 2, 2023
barneygale
added a commit
to barneygale/cpython
that referenced
this issue
May 6, 2023
barneygale
added a commit
that referenced
this issue
May 6, 2023
…103549) Improve performance of `pathlib.Path.absolute()` and `cwd()` by joining paths only when necessary. Also improve performance of `PurePath.is_absolute()` on Posix by skipping path parsing and normalization.
jbower-fb
pushed a commit
to jbower-fb/cpython-jbowerfb
that referenced
this issue
May 8, 2023
pythonGH-103549) Improve performance of `pathlib.Path.absolute()` and `cwd()` by joining paths only when necessary. Also improve performance of `PurePath.is_absolute()` on Posix by skipping path parsing and normalization.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
3.12
bugs and security fixes
performance
Performance or resource usage
topic-pathlib
type-feature
A feature request or enhancement
Two optimizations are possible:
is_absolute()
can pass the unnormalized path toos.path.isabs()
absolute()
on an empty path (orPath.cwd()
) can avoid joining an empty string onto the working directory (thus avoiding a call toos.path.join()
), and short-circuit the string normalization (as the result ofgetcwd()
is fully normalized)Linked PRs
pathlib.Path.[is_]absolute()
#103549The text was updated successfully, but these errors were encountered: