mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-08 03:40:27 +01:00
Improve replaceAll
This commit is contained in:
parent
592adccf81
commit
9c8fcc4286
@ -269,21 +269,18 @@ final class PaletteImpl implements Palette, Cloneable {
|
|||||||
@Override
|
@Override
|
||||||
public void replaceAll(@NotNull EntryFunction function) {
|
public void replaceAll(@NotNull EntryFunction function) {
|
||||||
int[] cache = sizeCache(maxSize());
|
int[] cache = sizeCache(maxSize());
|
||||||
|
AtomicInteger arrayIndex = new AtomicInteger();
|
||||||
AtomicInteger count = new AtomicInteger();
|
AtomicInteger count = new AtomicInteger();
|
||||||
// Fill cache with values
|
|
||||||
getAll((x, y, z, value) -> {
|
getAll((x, y, z, value) -> {
|
||||||
final int newValue = function.apply(x, y, z, value);
|
final int newValue = function.apply(x, y, z, value);
|
||||||
final int index = count.getPlain();
|
final int index = arrayIndex.getPlain();
|
||||||
count.setPlain(index + 1);
|
arrayIndex.setPlain(index + 1);
|
||||||
cache[index] = newValue != value ? getPaletteIndex(newValue) : value;
|
cache[index] = newValue != value ? getPaletteIndex(newValue) : value;
|
||||||
|
if (newValue != 0) count.setPlain(count.getPlain() + 1);
|
||||||
});
|
});
|
||||||
// Set values to final arrayUse setAll for generation
|
// Update palette content
|
||||||
count.setPlain(0);
|
updateAll(cache);
|
||||||
setAll((x, y, z) -> {
|
this.count = count.getPlain();
|
||||||
final int index = count.getPlain();
|
|
||||||
count.setPlain(index + 1);
|
|
||||||
return cache[index];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user