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:
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user