Skip to content

Commit d7e019b

Browse files
committed
pythonGH-119518: Stop interning strings in pathlib
Remove `sys.intern(str(x))` calls when normalizing a path in pathlib. This speeds up `str(Path('foo/bar'))` by about 10%.
1 parent 7bd6ebf commit d7e019b

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

‎Lib/pathlib/_local.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def _parse_path(cls, path):
273273
elif len(drv_parts) == 6:
274274
# e.g. //?/unc/server/share
275275
root = sep
276-
parsed = [sys.intern(str(x)) for x in rel.split(sep) if x and x != '.']
276+
parsed = [x for x in rel.split(sep) if x and x != '.']
277277
return drv, root, parsed
278278

279279
@property
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Speed up normalization of :class:`pathlib.PurePath` and
2+
:class:`~pathlib.Path` objects by not interning string parts.

0 commit comments

Comments
 (0)