summaryrefslogtreecommitdiffstats
path: root/Misc/NEWS.d
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-11-04 19:29:57 (GMT)
committerGitHub <noreply@github.com>2024-11-04 19:29:57 (GMT)
commit9b7294c3a560f43f1e26a0f48c258829076d6464 (patch)
treebc6936818bae49242cebd431545cd380e853149a /Misc/NEWS.d
parent2e95c5ba3bf7e5004c7e2304afda4a8f8e2443a7 (diff)
downloadcpython-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 'Misc/NEWS.d')
-rw-r--r--Misc/NEWS.d/next/Library/2024-11-03-14-43-51.gh-issue-126363.Xus7vU.rst2
1 files changed, 2 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Library/2024-11-03-14-43-51.gh-issue-126363.Xus7vU.rst b/Misc/NEWS.d/next/Library/2024-11-03-14-43-51.gh-issue-126363.Xus7vU.rst
new file mode 100644
index 0000000..20fea9b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-11-03-14-43-51.gh-issue-126363.Xus7vU.rst
@@ -0,0 +1,2 @@
+Speed up pattern parsing in :meth:`pathlib.Path.glob` by skipping creation
+of a :class:`pathlib.Path` object for the pattern.