Skip to content
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

Improve glob performance #113

Merged
merged 2 commits into from Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/106.feature.rst
@@ -0,0 +1 @@
Bypass ZipFile.namelist in glob for better performance.
2 changes: 1 addition & 1 deletion tests/test_complexity.py
Expand Up @@ -85,7 +85,7 @@ def test_glob_depth(self):
max_n=100,
min_n=1,
)
assert best <= big_o.complexities.Quadratic
assert best <= big_o.complexities.Linear

@pytest.mark.flaky
def test_glob_width(self):
Expand Down
3 changes: 2 additions & 1 deletion zipp/__init__.py
Expand Up @@ -402,7 +402,8 @@ def glob(self, pattern):
prefix = re.escape(self.at)
tr = Translator(seps='/')
matches = re.compile(prefix + tr.translate(pattern)).fullmatch
return map(self._next, filter(matches, self.root.namelist()))
names = (data.filename for data in self.root.filelist)
return map(self._next, filter(matches, names))

def rglob(self, pattern):
return self.glob(f'**/{pattern}')
Expand Down