diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-11-04 19:29:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-04 19:29:57 (GMT) |
commit | 9b7294c3a560f43f1e26a0f48c258829076d6464 (patch) | |
tree | bc6936818bae49242cebd431545cd380e853149a /Lib/trace.py | |
parent | 2e95c5ba3bf7e5004c7e2304afda4a8f8e2443a7 (diff) | |
download | cpython-9b7294c3a560f43f1e26a0f48c258829076d6464.zip cpython-9b7294c3a560f43f1e26a0f48c258829076d6464.tar.gz cpython-9b7294c3a560f43f1e26a0f48c258829076d6464.tar.bz2 |
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>
Diffstat (limited to 'Lib/trace.py')
0 files changed, 0 insertions, 0 deletions