0

nbt: small optimisation to list reading

Don't use .append(), we already know the final length. Instead,
have python initialise the list of a certain size and set the elements
in it.

Makes the function like 4% faster.
This commit is contained in:
Nicolas F
2019-12-26 17:28:51 +01:00
parent 0b74d26c49
commit a9fa06f019

View File

@@ -167,9 +167,9 @@ class NBTFileReader(object):
length = self._uint.unpack(self._file.read(4))[0] length = self._uint.unpack(self._file.read(4))[0]
read_method = self._read_tagmap[tagid] read_method = self._read_tagmap[tagid]
l = [] l = [None] * length
for _ in range(length): for i in range(length):
l.append(read_method()) l[i] = read_method()
return l return l
def _read_tag_compound(self): def _read_tag_compound(self):