mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-115060: Speed up pathlib.Path.glob()
by removing redundant regex matching (#115061)
When expanding and filtering paths for a `**` wildcard segment, build an `re.Pattern` object from the subsequent pattern parts, rather than the entire pattern, and match against the `os.DirEntry` object prior to instantiating a path object. Also skip compiling a pattern when expanding a `*` wildcard segment.
This commit is contained in:
parent
9d1a353230
commit
6f93b4df92
4 changed files with 76 additions and 28 deletions
|
@ -1250,6 +1250,19 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
|
|||
self.assertEqual(expect, set(p.glob(P(pattern))))
|
||||
self.assertEqual(expect, set(p.glob(FakePath(pattern))))
|
||||
|
||||
@needs_symlinks
|
||||
def test_glob_dot(self):
|
||||
P = self.cls
|
||||
with os_helper.change_cwd(P(self.base, "dirC")):
|
||||
self.assertEqual(
|
||||
set(P('.').glob('*')), {P("fileC"), P("novel.txt"), P("dirD")})
|
||||
self.assertEqual(
|
||||
set(P('.').glob('**')), {P("fileC"), P("novel.txt"), P("dirD"), P("dirD/fileD"), P(".")})
|
||||
self.assertEqual(
|
||||
set(P('.').glob('**/*')), {P("fileC"), P("novel.txt"), P("dirD"), P("dirD/fileD")})
|
||||
self.assertEqual(
|
||||
set(P('.').glob('**/*/*')), {P("dirD/fileD")})
|
||||
|
||||
def test_rglob_pathlike(self):
|
||||
P = self.cls
|
||||
p = P(self.base, "dirC")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue