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