From 6e586da83e89865c87340d602c0d416dff220fcb Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 11 Sep 2021 16:38:01 +0100 Subject: [PATCH] Some code cleanup - Simplify MaskFilter slightly - Improve thread safety of LocalBlockVectorSet - Simplify if statement in SingleThreadQueueExtent - Better error in MathMan#tripleSearchCoords for handling of the error in some cases --- .../core/extent/filter/MaskFilter.java | 21 +++++-------------- .../core/math/LocalBlockVectorSet.java | 6 +++--- .../SingleThreadQueueExtent.java | 2 -- .../fastasyncworldedit/core/util/MathMan.java | 2 +- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/MaskFilter.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/MaskFilter.java index e68de30bc..d56fc71c3 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/MaskFilter.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/MaskFilter.java @@ -7,7 +7,6 @@ import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Supplier; /** * Filter with an attached Mask used for deciding whether a block is eligible for being applied to. @@ -16,25 +15,15 @@ import java.util.function.Supplier; */ public class MaskFilter extends DelegateFilter { - private final Supplier supplier; private final Mask mask; private final AtomicInteger changes; - public MaskFilter(T other, Mask mask) { - this(other, () -> mask); + public MaskFilter(T other, Mask root) { + this(other, root, new AtomicInteger()); } - public MaskFilter(T other, Supplier supplier) { - this(other, supplier, supplier.get()); - } - - public MaskFilter(T other, Supplier supplier, Mask root) { - this(other, supplier, root, new AtomicInteger()); - } - - public MaskFilter(T other, Supplier supplier, Mask root, AtomicInteger changes) { + public MaskFilter(T other, Mask root, AtomicInteger changes) { super(other); - this.supplier = supplier; this.mask = root; this.changes = changes; } @@ -63,12 +52,12 @@ public class MaskFilter extends DelegateFilter { @Override public MaskFilter newInstance(Filter other) { - return new MaskFilter<>(other, supplier); + return new MaskFilter<>(other, mask); } @Override public Filter fork() { - return new MaskFilter<>(getParent().fork(), mask::copy, mask.copy(), changes); + return new MaskFilter<>(getParent().fork(), mask.copy(), changes); } } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/math/LocalBlockVectorSet.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/math/LocalBlockVectorSet.java index 3e7ecdd16..23759c03b 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/math/LocalBlockVectorSet.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/math/LocalBlockVectorSet.java @@ -17,8 +17,8 @@ import java.util.Set; public class LocalBlockVectorSet implements Set { private final SparseBitSet set; - private int offsetX; - private int offsetZ; + private volatile int offsetX; + private volatile int offsetZ; public LocalBlockVectorSet() { offsetX = offsetZ = Integer.MAX_VALUE; @@ -211,7 +211,7 @@ public class LocalBlockVectorSet implements Set { } public boolean add(int x, int y, int z) { - if (offsetX == Integer.MAX_VALUE) { + if (offsetX == Integer.MAX_VALUE || offsetZ == Integer.MAX_VALUE) { offsetX = x; offsetZ = z; } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/SingleThreadQueueExtent.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/SingleThreadQueueExtent.java index b1bd87682..8f1c1c489 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/SingleThreadQueueExtent.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/SingleThreadQueueExtent.java @@ -305,8 +305,6 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen if (chunk != null) { lastPair = pair; lastChunk = chunk; - } - if (chunk != null) { return chunk; } final int size = chunks.size(); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MathMan.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MathMan.java index c53df7ec7..b4e43f150 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MathMan.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MathMan.java @@ -201,7 +201,7 @@ public class MathMan { */ public static int tripleSearchCoords(int x, int y, int z) { if (x > 1023 || x < -1024 || y > 255 || y < -256 || z > 1023 || z < -1024) { - throw new IndexOutOfBoundsException(String.format("Check range on x=%s, y=%s and z=%s!", x, y, z)); + throw new UnsupportedOperationException(String.format("Check range on x=%s, y=%s and z=%s!", x, y, z)); } int b1 = Math.abs(y) & 0xff; int b3 = x & 0xff;