Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-101362: Omit path anchor frompathlib.PurePath()._parts#102476

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

barneygale
Copy link
Contributor

@barneygalebarneygale commentedMar 6, 2023
edited
Loading

Improve performance of path construction by skipping the addition of the path anchor (drive + root) to the internal_parts list. Rename this attribute to_tail for clarity.

Also:

  • Simplify the implementations ofname,parent, andparents a little.
  • Optimize_make_child_relpath() by building the new string path with naive string concatination rather than_format_parsed_parts().
  • Optimize__hash__() and__eq__() by referring to theunsplit case-normalized path.
  • Optimize__lt__() etc by referring to thenaively split case-normalized path (i.e. split onsep without consideration of anchor)

The publicparts tuple is unaffected.

$ ./python -m timeit -s 'from pathlib import PureWindowsPath as P' 'P("C:/foo/bar.py")'100000 loops, best of 5: 1.98 usec per loop  # before200000 loops, best of 5: 1.75 usec per loop  # after

Improve performance of path construction by skipping the addition of thepath anchor (`drive + root`) to the internal `_parts` list. This changeallows us to simplify the implementations of `joinpath()`, `name`,`parent`, and `parents` a little. The public `parts` tuple is unaffected.
@barneygale
Copy link
ContributorAuthor

barneygale commentedMar 6, 2023
edited
Loading

I'm not sure about this change - I don't like how it makes_parts andparts have different contents. Too subtle for future maintainers to pick up on, perhaps?

edit: addressed by renaming_parts to_tail.

@barneygalebarneygale added performancePerformance or resource usage topic-pathlib labelsMar 6, 2023
@barneygale
Copy link
ContributorAuthor

barneygale commentedMar 12, 2023
edited
Loading

This change is necessary in order to efficiently fix#65238, which is required before we can return unnormalized paths from__fspath__() in#102783.

@barneygale
Copy link
ContributorAuthor

barneygale commentedApr 3, 2023
edited
Loading

Updated timings:

$ ./python -m timeit -s 'from pathlib import PureWindowsPath as P' 'str(P("C:/foo/bar.py"))'100000 loops, best of 5: 3.92 usec per loop  # before100000 loops, best of 5: 3.57 usec per loop  # after

Something like a 10% speedup.

AlexWaygood reacted with rocket emoji

@barneygalebarneygale merged commit2c673d5 intopython:mainApr 9, 2023
warsaw pushed a commit to warsaw/cpython that referenced this pull requestApr 11, 2023
…ythonGH-102476)Improve performance of path construction by skipping the addition of the path anchor (`drive + root`) to the internal `_parts` list. Rename this attribute to `_tail` for clarity.
aisk pushed a commit to aisk/cpython that referenced this pull requestApr 18, 2023
…ythonGH-102476)Improve performance of path construction by skipping the addition of the path anchor (`drive + root`) to the internal `_parts` list. Rename this attribute to `_tail` for clarity.
anjakefala added a commit to saulpw/visidata that referenced this pull requestJun 27, 2023
`pathlib.Path._parts` has been removed in Python 3.12:python/cpython#102476Switch to pathlib.Path.parts which is a tuple.Closes#1934
anjakefala added a commit to saulpw/visidata that referenced this pull requestJun 27, 2023
`pathlib.Path._parts` has been removed in Python 3.12:python/cpython#102476Switch to pathlib.Path.parts which is a tuple.Closes#1934
anjakefala added a commit to saulpw/visidata that referenced this pull requestJul 16, 2023
`pathlib.Path._parts` has been removed in Python 3.12:python/cpython#102476Switch to pathlib.Path.parts which is a tuple.Closes#1934
anjakefala added a commit to saulpw/visidata that referenced this pull requestJul 17, 2023
`pathlib.Path._parts` has been removed in Python 3.12:python/cpython#102476Switch to pathlib.Path.parts which is a tuple.Closes#1934
anjakefala added a commit to saulpw/visidata that referenced this pull requestJul 17, 2023
`pathlib.Path._parts` has been removed in Python 3.12:python/cpython#102476Switch to pathlib.Path.parts which is a tuple.Closes#1934
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@AlexWaygoodAlexWaygoodAlexWaygood left review comments

Assignees
No one assigned
Labels
performancePerformance or resource usagetopic-pathlib
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@barneygale@AlexWaygood@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp