Optimize ChunkProviderServer's chunk level checking helper methods

These can be hot functions (i.e entity ticking and block ticking),
so inline where possible, and avoid the abstraction of the
Either class.
This commit is contained in:
Spottedleaf
2020-04-16 20:47:15 -07:00
parent 416b2f43e3
commit b415ceb617
2 changed files with 70 additions and 15 deletions

View File

@@ -7,7 +7,7 @@ In order to get chunk values, we shouldn't need to create
an optional each time.
diff --git a/src/main/java/com/mojang/datafixers/util/Either.java b/src/main/java/com/mojang/datafixers/util/Either.java
index a90adac7b..4bb621d57 100644
index a90adac7b..3f65fe710 100644
--- a/src/main/java/com/mojang/datafixers/util/Either.java
+++ b/src/main/java/com/mojang/datafixers/util/Either.java
@@ -0,0 +0,0 @@ public abstract class Either<L, R> implements App<Either.Mu<R>, L> {
@@ -15,20 +15,16 @@ index a90adac7b..4bb621d57 100644
private static final class Left<L, R> extends Either<L, R> {
- private final L value;
+ private final L value; private final Optional<L> valueOptional; // Paper - reduce the optional allocation...
+ private final L value; private Optional<L> valueOptional; // Paper - reduce the optional allocation...
public Left(final L value) {
- this.value = value;
+ this.value = value; this.valueOptional = value != null ? Optional.of(value) : Optional.empty(); // Paper - reduce the optional allocation...
}
@Override
this.value = value;
@@ -0,0 +0,0 @@ public abstract class Either<L, R> implements App<Either.Mu<R>, L> {
@Override
public Optional<L> left() {
- return Optional.of(value);
+ return this.valueOptional; // Paper - reduce the optional allocation...
+ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - reduce the optional allocation...
}
@Override
@@ -37,20 +33,16 @@ index a90adac7b..4bb621d57 100644
private static final class Right<L, R> extends Either<L, R> {
- private final R value;
+ private final R value; private final Optional<R> valueOptional; // Paper - reduce the optional allocation...
+ private final R value; private Optional<R> valueOptional; // Paper - reduce the optional allocation...
public Right(final R value) {
- this.value = value;
+ this.value = value; this.valueOptional = value != null ? Optional.of(value) : Optional.empty(); // Paper - reduce the optional allocation...
}
@Override
this.value = value;
@@ -0,0 +0,0 @@ public abstract class Either<L, R> implements App<Either.Mu<R>, L> {
@Override
public Optional<R> right() {
- return Optional.of(value);
+ return this.valueOptional; // Paper - reduce the optional allocation...
+ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - reduce the optional allocation...
}
@Override