diff --git a/newsfragments/106.feature.rst b/newsfragments/106.feature.rst new file mode 100644 index 0000000..5eff578 --- /dev/null +++ b/newsfragments/106.feature.rst @@ -0,0 +1 @@ +Bypass ZipFile.namelist in glob for better performance. \ No newline at end of file diff --git a/tests/test_complexity.py b/tests/test_complexity.py index d2adcf1..e2445e1 100644 --- a/tests/test_complexity.py +++ b/tests/test_complexity.py @@ -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): diff --git a/zipp/__init__.py b/zipp/__init__.py index 093b1e0..6d05d9a 100644 --- a/zipp/__init__.py +++ b/zipp/__init__.py @@ -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}')