Reduce Either Optional allocation

In order to get chunk values, we shouldn't need to create
an optional each time.
This commit is contained in:
Spottedleaf 2020-04-06 18:35:09 -07:00
parent aa8e04867f
commit 60c674b750

View file

@ -0,0 +1,38 @@
--- a/com/mojang/datafixers/util/Either.java
+++ b/com/mojang/datafixers/util/Either.java
@@ -22,7 +22,7 @@
}
private static final class Left<L, R> extends Either<L, R> {
- private final L value;
+ private final L value; private Optional<L> valueOptional; // Paper - Perf: Reduce Either Optional allocation
public Left(final L value) {
this.value = value;
@@ -51,7 +51,7 @@
@Override
public Optional<L> left() {
- return Optional.of(value);
+ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - Perf: Reduce Either Optional allocation
}
@Override
@@ -83,7 +83,7 @@
}
private static final class Right<L, R> extends Either<L, R> {
- private final R value;
+ private final R value; private Optional<R> valueOptional; // Paper - Perf: Reduce Either Optional allocation
public Right(final R value) {
this.value = value;
@@ -117,7 +117,7 @@
@Override
public Optional<R> right() {
- return Optional.of(value);
+ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - Perf: Reduce Either Optional allocation
}
@Override