turns out GZipStream.ReadByte() allocates a 1 byte array each time, so avoid that

This commit is contained in:
UnknownShadow200 2017-09-20 14:47:49 +10:00
parent 813d1b0f14
commit 0b7fb5899c

View File

@ -78,14 +78,17 @@ namespace MCGalaxy.Levels.IO {
} }
static void ReadCustomBlocksSection(Level lvl, Stream gs) { 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; int index = 0;
for (int y = 0; y < lvl.ChunksY; y++) for (int y = 0; y < lvl.ChunksY; y++)
for (int z = 0; z < lvl.ChunksZ; z++) for (int z = 0; z < lvl.ChunksZ; z++)
for (int x = 0; x < lvl.ChunksX; x++) 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]; byte[] chunk = new byte[16 * 16 * 16];
gs.Read(chunk, 0, chunk.Length); gs.Read(chunk, 0, chunk.Length);
lvl.CustomBlocks[index] = chunk; lvl.CustomBlocks[index] = chunk;