cpython/Lib/pathlib
Barney Gale 9b7294c3a5
GH-126363: Speed up pattern parsing in `pathlib.Path.glob()` (#126364)
The implementation of `Path.glob()` does rather a hacky thing: it calls
`self.with_segments()` to convert the given pattern to a `Path` object, and
then peeks at the private `_raw_path` attribute to see if pathlib removed a
trailing slash from the pattern.

In this patch, we make `glob()` use a new `_parse_pattern()` classmethod
that splits the pattern into parts while preserving information about any
trailing slash. This skips the cost of creating a `Path` object, and avoids
some path anchor normalization, which makes `Path.glob()` slightly faster.
But mostly it's about making the code less naughty.

Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
2024-11-04 19:29:57 +00:00
..
__init__.py GH-73991: Rework `pathlib.Path.copytree()` into `copy()` (#122369) 2024-08-11 22:43:18 +01:00
_abc.py GH-125413: pathlib ABCs: use `scandir()` to speed up `walk()` (#126262) 2024-11-01 18:52:00 +00:00
_local.py GH-126363: Speed up pattern parsing in `pathlib.Path.glob()` (#126364) 2024-11-04 19:29:57 +00:00
_os.py GH-122890: Fix low-level error handling in `pathlib.Path.copy()` (#122897) 2024-08-24 15:11:39 +01:00