8000 bpo-37935: Improve performance of pathlib.scandir() by ShaiAvr · Pull Request #15331 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

bpo-37935: Improve performance of pathlib.scandir() #15331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,21 +519,21 @@ def __init__(self, pat, child_parts):
def _select_from(self, parent_path, is_dir, exists, scandir):
try:
cf = parent_path._flavour.casefold
entries = list(scandir(parent_path))
for entry in entries:
entry_is_dir = False
try:
entry_is_dir = entry.is_dir()
except OSError as e:
if not _ignore_error(e):
raise
if not self.dironly or entry_is_dir:
name = entry.name
casefolded = cf(name)
if self.pat.match(casefolded):
path = parent_path._make_child_relpath(name)
for p in self.successor._select_from(path, is_dir, exists, scandir):
yield p
with scandir(parent_path) as entries:
for entry in entries:
entry_is_dir = False
try:
entry_is_dir = entry.is_dir()
except OSError as e:
if not _ignore_error(e):
raise
if not self.dironly or entry_is_dir:
name = entry.name
casefolded = cf(name)
if self.pat.match(casefolded):
path = parent_path._make_child_relpath(name)
for p in self.successor._select_from(path, is_dir, exists, scandir):
yield p
except PermissionError:
return

Expand All @@ -547,18 +547,18 @@ def __init__(self, pat, child_parts):
def _iterate_directories(self, parent_path, is_dir, scandir):
yield parent_path
try:
entries = list(scandir(parent_path))
for entry in entries:
entry_is_dir = False
try:
entry_is_dir = entry.is_dir()
except OSError as e:
if not _ignore_error(e):
raise
if entry_is_dir and not entry.is_symlink():
path = parent_path._make_child_relpath(entry.name)
for p in self._iterate_directories(path, is_dir, scandir):
yield p
with scandir(parent_path) as entries:
for entry in entries:
entry_is_dir = False
try:
entry_is_dir = entry.is_dir()
except OSError as e:
if not _ignore_error(e):
raise
if entry_is_dir and not entry.is_symlink():
path = parent_path._make_child_relpath(entry.name)
for p in self._iterate_directories(path, is_dir, scandir):
yield p
except PermissionError:
return

Expand Down
0