]> granicus.if.org Git - python/commitdiff
Issue #18585: speed zipfile import by only generating zipfile._ZipDecryptor on demand
authorDaniel Holth <dholth@fastmail.fm>
Fri, 3 Jan 2014 04:17:21 +0000 (23:17 -0500)
committerDaniel Holth <dholth@fastmail.fm>
Fri, 3 Jan 2014 04:17:21 +0000 (23:17 -0500)
Lib/zipfile.py

index fad52a246d5a194f91939bde3c17826760a827dc..173d99080c6e331b5fc5cd314cbd68341c7ceaf6 100644 (file)
@@ -475,13 +475,15 @@ class _ZipDecrypter:
                     crc = ((crc >> 1) & 0x7FFFFFFF)
             table[i] = crc
         return table
-    crctable = _GenerateCRCTable()
+    crctable = None
 
     def _crc32(self, ch, crc):
         """Compute the CRC32 primitive on one byte."""
         return ((crc >> 8) & 0xffffff) ^ self.crctable[(crc ^ ch) & 0xff]
 
     def __init__(self, pwd):
+        if _ZipDecrypter.crctable is None:
+            _ZipDecrypter.crctable = _ZipDecrypter._GenerateCRCTable()
         self.key0 = 305419896
         self.key1 = 591751049
         self.key2 = 878082192