mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
GH-125413: pathlib ABCs: use scandir()
to speed up glob()
(#126261)
Use the new `PathBase.scandir()` method in `PathBase.glob()`, which greatly reduces the number of `PathBase.stat()` calls needed when globbing. There are no user-facing changes, because the pathlib ABCs are still private and `Path.glob()` doesn't use the implementation in its superclass.
This commit is contained in:
parent
464a7a91d0
commit
68a51e0178
3 changed files with 10 additions and 25 deletions
|
@ -1633,8 +1633,10 @@ class DummyPathTest(DummyPurePathTest):
|
|||
p.joinpath('linkA').symlink_to('fileA')
|
||||
p.joinpath('brokenLink').symlink_to('non-existing')
|
||||
p.joinpath('linkB').symlink_to('dirB', target_is_directory=True)
|
||||
p.joinpath('dirA', 'linkC').symlink_to(parser.join('..', 'dirB'))
|
||||
p.joinpath('dirB', 'linkD').symlink_to(parser.join('..', 'dirB'))
|
||||
p.joinpath('dirA', 'linkC').symlink_to(
|
||||
parser.join('..', 'dirB'), target_is_directory=True)
|
||||
p.joinpath('dirB', 'linkD').symlink_to(
|
||||
parser.join('..', 'dirB'), target_is_directory=True)
|
||||
p.joinpath('brokenLinkLoop').symlink_to('brokenLinkLoop')
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -2479,7 +2481,7 @@ class DummyPathTest(DummyPurePathTest):
|
|||
if i % 2:
|
||||
link.symlink_to(P(self.base, "dirE", "nonexistent"))
|
||||
else:
|
||||
link.symlink_to(P(self.base, "dirC"))
|
||||
link.symlink_to(P(self.base, "dirC"), target_is_directory=True)
|
||||
|
||||
self.assertEqual(len(set(base.glob("*"))), 100)
|
||||
self.assertEqual(len(set(base.glob("*/"))), 50)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue