From a9fa06f0192bd767fc6d323921cdb62232d967d1 Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Thu, 26 Dec 2019 17:28:51 +0100 Subject: [PATCH] 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. --- overviewer_core/nbt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/overviewer_core/nbt.py b/overviewer_core/nbt.py index cbb6c71..7a8ee46 100644 --- a/overviewer_core/nbt.py +++ b/overviewer_core/nbt.py @@ -167,9 +167,9 @@ class NBTFileReader(object): length = self._uint.unpack(self._file.read(4))[0] read_method = self._read_tagmap[tagid] - l = [] - for _ in range(length): - l.append(read_method()) + l = [None] * length + for i in range(length): + l[i] = read_method() return l def _read_tag_compound(self):