From 8ba96f9b133203e179a11b9e18f4bf786c83f6a3 Mon Sep 17 00:00:00 2001 From: Caleb Deveraux Date: Sun, 3 Oct 2010 23:28:55 -0600 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 847dd0a..d191e34 100644 --- a/mclevel.py +++ b/mclevel.py @@ -1573,10 +1573,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 59eeb0f..db02678 100644 --- a/nbt.py +++ b/nbt.py @@ -233,7 +233,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: @@ -347,7 +347,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))