From b766af613cbff0462aa105e66fe983d0cb8d52f3 Mon Sep 17 00:00:00 2001 From: Caleb Deveraux Date: Mon, 4 Oct 2010 13:28:55 +0800 Subject: [PATCH] Avoid creating temporary lists where possible --- mclevel.py | 5 +---- nbt.py | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/mclevel.py b/mclevel.py index e5fe4d2..b263996 100644 --- a/mclevel.py +++ b/mclevel.py @@ -1564,10 +1564,7 @@ class MCInfdevOldLevel(MCLevel): playerFilePath = os.path.join(self.worldDir, "players") if os.path.exists(playerFilePath): - playerDats = os.listdir(playerFilePath); - playerDats = filter(lambda x:x.endswith(".dat"), playerDats) - players = map(lambda x:x[:-4], playerDats); - self.players = players + self.players = [x[:-4] for x in os.listdir(playerFilePath) if x.endswith(".dat")] self.preloadChunkPaths(); diff --git a/nbt.py b/nbt.py index f15d3fd..455800b 100644 --- a/nbt.py +++ b/nbt.py @@ -238,7 +238,7 @@ class TAG_Compound(TAG_Value, collections.MutableMapping): def nbt_length(self): - return sum(map(lambda x:(x.nbt_length()+len(x.name)+3), self.value))+1; + return sum(x.nbt_length() + len(x.name) + 3 for x in self.value) + 1; def write_value(self, buf): for i in self.value: @@ -352,7 +352,7 @@ class TAG_List(TAG_Value, collections.MutableSequence): self.list.insert(i, v); def nbt_length(self): - return 5 + sum(map(lambda x:x.nbt_length(), self.list)); + return 5 + sum(x.nbt_length() for x in self.list) def write_value(self, buf): buf.write(struct.pack(TAGfmt, self.list_type))