Free memory when clearing palette

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-01-08 08:29:56 +01:00
parent 42dc264c93
commit 5e41b148a4
2 changed files with 4 additions and 6 deletions

View File

@ -49,8 +49,8 @@ public final class Section implements Writeable {
} }
public void clear() { public void clear() {
this.blockPalette = Palette.blocks(); this.blockPalette.fill(0);
this.biomePalette = Palette.biomes(); this.biomePalette.fill(0);
this.skyLight = new byte[0]; this.skyLight = new byte[0];
this.blockLight = new byte[0]; this.blockLight = new byte[0];
} }

View File

@ -154,15 +154,13 @@ final class PaletteImpl implements Palette, Cloneable {
// Initialize the section // Initialize the section
this.values = values = new long[(size + valuesPerLong - 1) / valuesPerLong]; this.values = values = new long[(size + valuesPerLong - 1) / valuesPerLong];
} }
if (placedAir) { if (placedAir) {
Arrays.fill(values, 0); this.values = new long[0];
this.count = 0; this.count = 0;
} else { } else {
long block = 0; long block = 0;
for (int i = 0; i < valuesPerLong; i++) { for (int i = 0; i < valuesPerLong; i++)
block |= (long) value << i * bitsPerEntry; block |= (long) value << i * bitsPerEntry;
}
Arrays.fill(values, block); Arrays.fill(values, block);
this.count = maxSize(); this.count = maxSize();
} }