mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-27 11:09:06 +00:00
Only compute if absent/present if compute is not needed (locking opts)
This commit is contained in:
@@ -892,7 +892,7 @@ public class IrisInterpolation {
|
||||
int fj = j;
|
||||
for (k = 0; k < d; k++) {
|
||||
int fk = k;
|
||||
hunk.set(i, j, k, cache.compute((k * w * h) + (j * w) + i, (p, v)
|
||||
hunk.set(i, j, k, cache.computeIfAbsent((k * w * h) + (j * w) + i, (p)
|
||||
-> getNoise3D(method, fi + xo, fj + yo, fk + zo,
|
||||
radX, radY, radZ, n)));
|
||||
}
|
||||
|
||||
@@ -103,8 +103,8 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
|
||||
entityCache = new KMap<>();
|
||||
|
||||
for (Entity i : ((World) w).getNearbyEntities(new BoundingBox(x, y, z, x + getWidth(), y + getHeight(), z + getHeight()))) {
|
||||
entityCache.compute(new IrisPosition(i.getLocation()),
|
||||
(k, v) -> v == null ? new KList<>() : v).add(i);
|
||||
entityCache.computeIfAbsent(new IrisPosition(i.getLocation()),
|
||||
k -> new KList<>()).add(i);
|
||||
}
|
||||
|
||||
for (IrisPosition i : entityCache.keySet()) {
|
||||
|
||||
@@ -32,8 +32,8 @@ import java.util.function.Supplier;
|
||||
|
||||
public class HyperLock {
|
||||
private final ConcurrentLinkedHashMap<Long, ReentrantLock> locks;
|
||||
private final BiFunction<? super Long, ? super ReentrantLock, ? extends ReentrantLock> accessor;
|
||||
private boolean enabled = true;
|
||||
private boolean fair = false;
|
||||
|
||||
public HyperLock() {
|
||||
this(1024, false);
|
||||
@@ -44,6 +44,7 @@ public class HyperLock {
|
||||
}
|
||||
|
||||
public HyperLock(int capacity, boolean fair) {
|
||||
this.fair = fair;
|
||||
locks = new ConcurrentLinkedHashMap.Builder<Long, ReentrantLock>()
|
||||
.initialCapacity(capacity)
|
||||
.maximumWeightedCapacity(capacity)
|
||||
@@ -54,7 +55,6 @@ public class HyperLock {
|
||||
})
|
||||
.concurrencyLevel(32)
|
||||
.build();
|
||||
accessor = (k, v) -> v == null ? new ReentrantLock(fair) : v;
|
||||
}
|
||||
|
||||
public void with(int x, int z, Runnable r) {
|
||||
@@ -123,7 +123,7 @@ public class HyperLock {
|
||||
}
|
||||
|
||||
private ReentrantLock getLock(int x, int z) {
|
||||
return locks.compute(Cache.key(x, z), accessor);
|
||||
return locks.computeIfAbsent(Cache.key(x, z), k -> new ReentrantLock(fair));
|
||||
}
|
||||
|
||||
public void lock(int x, int z) {
|
||||
|
||||
@@ -499,11 +499,7 @@ public class VolmitSender implements CommandSender {
|
||||
|
||||
public void sendDecreeHelpNode(VirtualDecreeCommand i) {
|
||||
if (isPlayer() || s instanceof CommandDummy) {
|
||||
sendMessageRaw(helpCache.compute(i.getPath(), (k, v) -> {
|
||||
if (v != null) {
|
||||
return v;
|
||||
}
|
||||
|
||||
sendMessageRaw(helpCache.computeIfAbsent(i.getPath(), (k) -> {
|
||||
String newline = "<reset>\n";
|
||||
|
||||
/// Command
|
||||
|
||||
@@ -85,7 +85,6 @@ public class GroupedExecutor {
|
||||
|
||||
public void queue(String q, NastyRunnable r) {
|
||||
mirror.compute(q, (k, v) -> k == null || v == null ? 1 : v + 1);
|
||||
|
||||
service.execute(() ->
|
||||
{
|
||||
try {
|
||||
@@ -95,7 +94,7 @@ public class GroupedExecutor {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mirror.compute(q, (k, v) -> v - 1);
|
||||
mirror.computeIfPresent(q, (k, v) -> v - 1);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -58,11 +58,11 @@ public class CachedConversionStream<T, V> extends BasicLayer implements Procedur
|
||||
|
||||
@Override
|
||||
public V get(double x, double z) {
|
||||
return cache.compute(stream.get(x, z), (k, v) -> v != null ? v : converter.apply(k));
|
||||
return cache.computeIfAbsent(stream.get(x, z), converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(double x, double y, double z) {
|
||||
return cache.compute(stream.get(x, y, z), (k, v) -> v != null ? v : converter.apply(k));
|
||||
return cache.computeIfAbsent(stream.get(x, y, z), converter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,11 +49,11 @@ public class CachedStream3D<T> extends BasicStream<T> implements ProceduralStrea
|
||||
|
||||
@Override
|
||||
public T get(double x, double z) {
|
||||
return cache.compute(new BlockPosition((int) x, -1, (int) z), (k, v) -> v != null ? v : stream.get((int) x, (int) z));
|
||||
return cache.computeIfAbsent(new BlockPosition((int) x, -1, (int) z), (k) -> stream.get((int) x, (int) z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(double x, double y, double z) {
|
||||
return cache.compute(new BlockPosition((int) x, (int) y, (int) z), (k, v) -> v != null ? v : stream.get((int) x, (int) y, (int) z));
|
||||
return cache.computeIfAbsent(new BlockPosition((int) x, (int) y, (int) z), (k) -> stream.get((int) x, (int) y, (int) z));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user