]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-101362: Optimise PurePath(PurePath(...)) (GH-101667)
authorBarney Gale <barney.gale@gmail.com>
Sun, 5 Mar 2023 23:50:21 +0000 (23:50 +0000)
committerGitHub <noreply@github.com>
Sun, 5 Mar 2023 23:50:21 +0000 (15:50 -0800)
commit6716254e71eeb4666fd6d1a13857832caad7b19f
treef069df2fd49f583efad636c7fc34f483b6d2a5e9
parent3e60e0213e9d884a2f4cef4df96956c5d4adde0a
GH-101362: Optimise PurePath(PurePath(...)) (GH-101667)

The previous `_parse_args()` method pulled the `_parts` out of any supplied `PurePath` objects; these were subsequently joined in `_from_parts()` using `os.path.join()`. This is actually a slower form of joining than calling `fspath()` on the path object, because it doesn't take advantage of the fact that the contents of `_parts` is normalized!

This reduces the time taken to run `PurePath("foo", "bar")` by ~20%, and the time taken to run `PurePath(p, "cheese")`, where `p = PurePath("/foo", "bar", "baz")`, by ~40%.

Automerge-Triggered-By: GH:AlexWaygood
Doc/library/pathlib.rst
Lib/pathlib.py
Lib/test/test_pathlib.py
Misc/NEWS.d/next/Library/2023-02-07-22-20-32.gh-issue-101362.Jlk6mt.rst [new file with mode: 0644]