memoize IntType constructor
[p2pool.git] / p2pool / util / pack.py
index 0c50fc2..ad6eaf7 100644 (file)
@@ -2,6 +2,7 @@ import binascii
 import struct
 
 import p2pool
+from p2pool.util import memoize
 
 class EarlyEnd(Exception):
     pass
@@ -161,10 +162,9 @@ class ListType(Type):
     
     def read(self, file):
         length, file = self._inner_size.read(file)
-        res = []
+        res = [None]*length
         for i in xrange(length):
-            item, file = self.type.read(file)
-            res.append(item)
+            res[i], file = self.type.read(file)
         return res, file
     
     def write(self, file, item):
@@ -187,6 +187,7 @@ class StructType(Type):
     def write(self, file, item):
         return file, struct.pack(self.desc, item)
 
+@memoize.fast_memoize_multiple_args
 class IntType(Type):
     __slots__ = 'bytes step format_str max'.split(' ')