Skip to content

Commit

Permalink
pythonGH-119518: Stop interning strings in pathlib
Browse files Browse the repository at this point in the history
Remove `sys.intern(str(x))` calls when normalizing a path in pathlib. This
speeds up `str(Path('foo/bar'))` by about 10%.
  • Loading branch information
barneygale committed Aug 26, 2024
1 parent 7bd6ebf commit d7e019b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/pathlib/_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _parse_path(cls, path):
elif len(drv_parts) == 6:
# e.g. //?/unc/server/share
root = sep
parsed = [sys.intern(str(x)) for x in rel.split(sep) if x and x != '.']
parsed = [x for x in rel.split(sep) if x and x != '.']
return drv, root, parsed

@property
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speed up normalization of :class:`pathlib.PurePath` and
:class:`~pathlib.Path` objects by not interning string parts.

0 comments on commit d7e019b

Please sign in to comment.