mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-25 18:19:14 +00:00
Only compute if absent/present if compute is not needed (locking opts)
This commit is contained in:
@@ -880,24 +880,8 @@ public class CommandStudio implements DecreeExecutor {
|
||||
}
|
||||
|
||||
String n3 = nn3;
|
||||
|
||||
objects.compute(n1, (k1, v1) ->
|
||||
{
|
||||
//noinspection ReplaceNullCheck
|
||||
if (v1 == null) {
|
||||
return new KMap<>();
|
||||
}
|
||||
|
||||
return v1;
|
||||
}).compute(n2, (k, v) ->
|
||||
{
|
||||
if (v == null) {
|
||||
return new KList<String>().qaddIfMissing(n3);
|
||||
}
|
||||
|
||||
v.addIfMissing(n3);
|
||||
return v;
|
||||
});
|
||||
objects.computeIfAbsent(n1, (k1) -> new KMap<>())
|
||||
.computeIfAbsent(n2, (k) -> new KList<>()).addIfMissing(n3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
}
|
||||
|
||||
public static IrisData get(File dataFolder) {
|
||||
return dataLoaders.compute(dataFolder, (k, v) -> v == null ? new IrisData(dataFolder) : v);
|
||||
return dataLoaders.computeIfAbsent(dataFolder, IrisData::new);
|
||||
}
|
||||
|
||||
public static void dereference() {
|
||||
|
||||
@@ -84,7 +84,7 @@ public class ResourceLoader<T extends IrisRegistrant> {
|
||||
o.put("fileMatch", new JSONArray(fm.toArray()));
|
||||
o.put("url", "./.iris/schema/" + getFolderName() + "-schema.json");
|
||||
File a = new File(getManager().getDataFolder(), ".iris/schema/" + getFolderName() + "-schema.json");
|
||||
J.attemptAsync(() -> IO.writeAll(a, new SchemaBuilder(objectClass, manager).compute().toString(4)));
|
||||
J.attemptAsync(() -> IO.writeAll(a, new SchemaBuilder(objectClass, manager).construct().toString(4)));
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ public class IrisProject {
|
||||
File a = new File(dm.getDataFolder(), ".iris/schema/snippet/" + snipType + "-schema.json");
|
||||
J.attemptAsync(() -> {
|
||||
try {
|
||||
IO.writeAll(a, new SchemaBuilder(i, dm).compute().toString(4));
|
||||
IO.writeAll(a, new SchemaBuilder(i, dm).construct().toString(4));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class SchemaBuilder {
|
||||
return a;
|
||||
}
|
||||
|
||||
public JSONObject compute() {
|
||||
public JSONObject construct() {
|
||||
JSONObject schema = new JSONObject();
|
||||
schema.put("$schema", "http://json-schema.org/draft-07/schema#");
|
||||
schema.put("$id", "http://volmit.com/iris-schema/" + root.getSimpleName().toLowerCase() + ".json");
|
||||
|
||||
@@ -167,11 +167,7 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
for (String i : objects) {
|
||||
e.queue(() -> {
|
||||
try {
|
||||
BlockVector bv = sizeCache.compute(i, (k, v) -> {
|
||||
if (v != null) {
|
||||
return v;
|
||||
}
|
||||
|
||||
BlockVector bv = sizeCache.computeIfAbsent(i, (k) -> {
|
||||
try {
|
||||
return IrisObject.sampleSize(getData().getObjectLoader().findFile(i));
|
||||
} catch (IOException ex) {
|
||||
@@ -207,11 +203,7 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
for (String j : entry.getValue()) {
|
||||
e.queue(() -> {
|
||||
try {
|
||||
BlockVector bv = sizeCache.compute(j, (k, v) -> {
|
||||
if (v != null) {
|
||||
return v;
|
||||
}
|
||||
|
||||
BlockVector bv = sizeCache.computeIfAbsent(j, (k) -> {
|
||||
try {
|
||||
return IrisObject.sampleSize(getData().getObjectLoader().findFile(j));
|
||||
} catch (IOException ioException) {
|
||||
|
||||
@@ -275,7 +275,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
if (!B.isFluid(c.getBlock(x & 15, y, z & 15).getBlockData())) {
|
||||
return;
|
||||
}
|
||||
boolean u = false;
|
||||
boolean u = false;
|
||||
if(B.isAir(c.getBlock(x & 15, y, z & 15).getRelative(BlockFace.DOWN).getBlockData()))
|
||||
{
|
||||
u = true;
|
||||
|
||||
@@ -329,12 +329,6 @@ public class PlannedStructure {
|
||||
public IrisObject rotated(IrisJigsawPiece piece, IrisObjectRotation rotation) {
|
||||
String key = piece.getObject() + "-" + rotation.hashCode();
|
||||
|
||||
return objectRotationCache.compute(key, (k, v) -> {
|
||||
if (v == null) {
|
||||
return rotation.rotateCopy(data.getObjectLoader().load(piece.getObject()));
|
||||
}
|
||||
|
||||
return v;
|
||||
});
|
||||
return objectRotationCache.computeIfAbsent(key, (k) -> rotation.rotateCopy(data.getObjectLoader().load(piece.getObject())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<BlockData> {
|
||||
return;
|
||||
}
|
||||
|
||||
positions.compute(Cache.key(rx, rz), (k, v) -> Objects.requireNonNullElseGet(v, (Supplier<KList<Integer>>) KList::new).qadd(yy));
|
||||
positions.computeIfAbsent(Cache.key(rx, rz), (k) -> new KList<>()).qadd(yy);
|
||||
|
||||
if (rz < 15 && mantle.get(xx, yy, zz + 1, MatterCavern.class) == null) {
|
||||
walls.put(new IrisPosition(rx, yy, rz + 1), c);
|
||||
|
||||
@@ -144,7 +144,7 @@ public class IrisBiomeCustom {
|
||||
KMap<IrisBiomeCustomSpawnType, JSONArray> groups = new KMap<>();
|
||||
|
||||
for (IrisBiomeCustomSpawn i : getSpawns()) {
|
||||
JSONArray g = groups.compute(i.getGroup(), (k, v) -> v != null ? v : new JSONArray());
|
||||
JSONArray g = groups.computeIfAbsent(i.getGroup(), (k) -> new JSONArray());
|
||||
JSONObject o = new JSONObject();
|
||||
o.put("type", "minecraft:" + i.getType().name().toLowerCase());
|
||||
o.put("weight", i.getWeight());
|
||||
|
||||
@@ -81,11 +81,7 @@ public class IrisObjectScale {
|
||||
return origin;
|
||||
}
|
||||
|
||||
return cache.compute(origin, (k, v) -> {
|
||||
if (v != null) {
|
||||
return v;
|
||||
}
|
||||
|
||||
return cache.computeIfAbsent(origin, (k) -> {
|
||||
KList<IrisObject> c = new KList<>();
|
||||
for (double i = minimumScale; i < maximumScale; i += (maximumScale - minimumScale) / (double) (Math.min(variations, 32))) {
|
||||
c.add(origin.scaled(i, getInterpolation()));
|
||||
|
||||
@@ -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