0
0
mirror of https://github.com/python/cpython.git synced 2024-11-27 23:47:29 +01:00
cpython/Misc/NEWS.d/next/Library/2024-11-03-14-43-51.gh-issue-126363.Xus7vU.rst
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

3 lines
126 B
ReStructuredText

Speed up pattern parsing in :meth:`pathlib.Path.glob` by skipping creation
of a :class:`pathlib.Path` object for the pattern.