mirror of
https://github.com/python/cpython.git
synced 2024-11-27 23:47:29 +01:00
9b7294c3a5
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>
3 lines
126 B
ReStructuredText
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.
|