Only compute if absent/present if compute is not needed (locking opts)

This commit is contained in:
cyberpwn
2021-09-13 09:31:56 -04:00
parent ca961e8498
commit eeab12ed86
18 changed files with 25 additions and 64 deletions

View File

@@ -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());

View File

@@ -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()));