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

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

View File

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