palette inlining

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-02-08 08:41:50 +01:00
parent 920bf62699
commit 09aea3c8d4

View File

@ -51,8 +51,7 @@ final class AdaptivePalette implements Palette {
if (x < 0 || y < 0 || z < 0) { if (x < 0 || y < 0 || z < 0) {
throw new IllegalArgumentException("Coordinates must be positive"); throw new IllegalArgumentException("Coordinates must be positive");
} }
Palette palette = switchFlexible(); flexiblePalette().set(x, y, z, value);
palette.set(x, y, z, value);
} }
@Override @Override
@ -72,14 +71,12 @@ final class AdaptivePalette implements Palette {
if (x < 0 || y < 0 || z < 0) { if (x < 0 || y < 0 || z < 0) {
throw new IllegalArgumentException("Coordinates must be positive"); throw new IllegalArgumentException("Coordinates must be positive");
} }
Palette palette = switchFlexible(); flexiblePalette().replace(x, y, z, operator);
palette.replace(x, y, z, operator);
} }
@Override @Override
public void replaceAll(@NotNull EntryFunction function) { public void replaceAll(@NotNull EntryFunction function) {
Palette palette = switchFlexible(); flexiblePalette().replaceAll(function);
palette.replaceAll(function);
} }
@Override @Override
@ -135,8 +132,8 @@ final class AdaptivePalette implements Palette {
return currentPalette; return currentPalette;
} }
Palette switchFlexible() { Palette flexiblePalette() {
var currentPalette = this.palette; SpecializedPalette currentPalette = this.palette;
if (currentPalette instanceof FilledPalette filledPalette) { if (currentPalette instanceof FilledPalette filledPalette) {
currentPalette = new FlexiblePalette(this); currentPalette = new FlexiblePalette(this);
currentPalette.fill(filledPalette.value()); currentPalette.fill(filledPalette.value());