From 0b7fb5899c6ef09b00b5f4125eafd423aa163345 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 20 Sep 2017 14:47:49 +1000 Subject: [PATCH] turns out GZipStream.ReadByte() allocates a 1 byte array each time, so avoid that --- MCGalaxy/Levels/IO/Importers/LvlImporter.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MCGalaxy/Levels/IO/Importers/LvlImporter.cs b/MCGalaxy/Levels/IO/Importers/LvlImporter.cs index a606189ae..2667cb588 100644 --- a/MCGalaxy/Levels/IO/Importers/LvlImporter.cs +++ b/MCGalaxy/Levels/IO/Importers/LvlImporter.cs @@ -78,14 +78,17 @@ namespace MCGalaxy.Levels.IO { } static void ReadCustomBlocksSection(Level lvl, Stream gs) { - if (gs.ReadByte() != 0xBD) return; + byte[] data = new byte[1]; + int read = gs.Read(data, 0, 1); + if (read == 0 || data[0] != 0xBD) return; int index = 0; for (int y = 0; y < lvl.ChunksY; y++) for (int z = 0; z < lvl.ChunksZ; z++) for (int x = 0; x < lvl.ChunksX; x++) { - if (gs.ReadByte() == 1) { + read = gs.Read(data, 0, 1); + if (read > 0 && data[0] == 1) { byte[] chunk = new byte[16 * 16 * 16]; gs.Read(chunk, 0, chunk.Length); lvl.CustomBlocks[index] = chunk;