Skip to content

Commit

Permalink
Merge pull request #113 from jaraco/feature/glob-perf
Browse files Browse the repository at this point in the history
Improve glob performance
  • Loading branch information
jaraco committed Mar 13, 2024
2 parents 4cceb49 + 171fa98 commit 48b72b8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
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

0 comments on commit 48b72b8

Please sign in to comment.