summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-02-12 02:58:47 (GMT)
committerGitHub <noreply@github.com>2020-02-12 02:58:47 (GMT)
commite5bd73632e77dc5ab0cab77e48e94ca5e354be8a (patch)
tree714f30a26206aeec8fd331b42ae095b638f216e5 /Lib/importlib
parente6be9b59a911626d6597fe148c32f0342bd2bd24 (diff)
downloadcpython-e5bd73632e77dc5ab0cab77e48e94ca5e354be8a.zip
cpython-e5bd73632e77dc5ab0cab77e48e94ca5e354be8a.tar.gz
cpython-e5bd73632e77dc5ab0cab77e48e94ca5e354be8a.tar.bz2
bpo-39595: Improve zipfile.Path performance (#18406)
* Improve zipfile.Path performance on zipfiles with a large number of entries. * 📜🤖 Added by blurb_it. * Add bpo to blurb * Sync with importlib_metadata 1.5 (6fe70ca) * Update blurb. * Remove compatibility code * Add stubs module, omitted from earlier commit Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/metadata.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/importlib/metadata.py b/Lib/importlib/metadata.py
index ae8ecf9..831f593 100644
--- a/Lib/importlib/metadata.py
+++ b/Lib/importlib/metadata.py
@@ -391,6 +391,7 @@ class FastPath:
def __init__(self, root):
self.root = root
+ self.base = os.path.basename(root).lower()
def joinpath(self, child):
return pathlib.Path(self.root, child)
@@ -413,12 +414,11 @@ class FastPath:
)
def is_egg(self, search):
- root_n_low = os.path.split(self.root)[1].lower()
-
+ base = self.base
return (
- root_n_low == search.normalized + '.egg'
- or root_n_low.startswith(search.prefix)
- and root_n_low.endswith('.egg'))
+ base == search.versionless_egg_name
+ or base.startswith(search.prefix)
+ and base.endswith('.egg'))
def search(self, name):
for child in self.children():
@@ -439,6 +439,7 @@ class Prepared:
prefix = ''
suffixes = '.dist-info', '.egg-info'
exact_matches = [''][:0]
+ versionless_egg_name = ''
def __init__(self, name):
self.name = name
@@ -448,6 +449,7 @@ class Prepared:
self.prefix = self.normalized + '-'
self.exact_matches = [
self.normalized + suffix for suffix in self.suffixes]
+ self.versionless_egg_name = self.normalized + '.egg'
class MetadataPathFinder(DistributionFinder):