mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-28 02:51:42 +01:00
Improve setAll constant write by 20%
This commit is contained in:
parent
83621e2ece
commit
fddd9dd934
@ -196,11 +196,15 @@ final class PaletteImpl implements Palette, Cloneable {
|
|||||||
@Override
|
@Override
|
||||||
public void setAll(@NotNull EntrySupplier supplier) {
|
public void setAll(@NotNull EntrySupplier supplier) {
|
||||||
int[] cache = sizeCache(maxSize());
|
int[] cache = sizeCache(maxSize());
|
||||||
// Fill cache with values
|
// Constants
|
||||||
|
final int size = this.size;
|
||||||
final int dimensionMinus = dimension - 1;
|
final int dimensionMinus = dimension - 1;
|
||||||
|
final int dimensionBitCount = this.dimensionBitCount;
|
||||||
|
final int shiftedDimensionBitCount = dimensionBitCount << 1;
|
||||||
|
// Fill cache with values
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
final int y = i >> (dimensionBitCount << 1);
|
final int y = i >> shiftedDimensionBitCount;
|
||||||
final int z = (i >> (dimensionBitCount)) & dimensionMinus;
|
final int z = (i >> (dimensionBitCount)) & dimensionMinus;
|
||||||
final int x = i & dimensionMinus;
|
final int x = i & dimensionMinus;
|
||||||
final int value = supplier.get(x, y, z);
|
final int value = supplier.get(x, y, z);
|
||||||
@ -221,15 +225,12 @@ final class PaletteImpl implements Palette, Cloneable {
|
|||||||
final int magicMask = MAGIC_MASKS[bitsPerEntry];
|
final int magicMask = MAGIC_MASKS[bitsPerEntry];
|
||||||
for (int i = 0; i < values.length; i++) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
long block = values[i];
|
long block = values[i];
|
||||||
for (int j = 0; j < valuesPerLong; j++) {
|
final int startIndex = i * valuesPerLong;
|
||||||
final int index = i * valuesPerLong + j;
|
final int maxIndex = startIndex + valuesPerLong > size ? size - startIndex : valuesPerLong;
|
||||||
if (index >= size) break;
|
for (int j = 0; j < maxIndex; j++) {
|
||||||
final int bitIndex = j * bitsPerEntry;
|
final int bitIndex = j * bitsPerEntry;
|
||||||
{
|
block &= ~((long) magicMask << bitIndex);
|
||||||
final long indexClear = (long) magicMask << bitIndex;
|
block |= (long) cache[startIndex + j] << bitIndex;
|
||||||
block &= ~indexClear;
|
|
||||||
block |= (long) cache[index] << bitIndex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
values[i] = block;
|
values[i] = block;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user