2020-04-17 05:47:15 +02:00
|
|
|
From 4e4969fe0412b6f2a2989a35215096c24266180a Mon Sep 17 00:00:00 2001
|
2020-04-13 00:31:14 +02:00
|
|
|
From: Spottedleaf <spottedleaf@spottedleaf.dev>
|
|
|
|
Date: Mon, 6 Apr 2020 18:35:09 -0700
|
|
|
|
Subject: [PATCH] Reduce Either Optional allocation
|
|
|
|
|
|
|
|
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
|
2020-04-17 05:47:15 +02:00
|
|
|
index a90adac7b..3f65fe710 100644
|
2020-04-13 00:31:14 +02:00
|
|
|
--- a/src/main/java/com/mojang/datafixers/util/Either.java
|
|
|
|
+++ b/src/main/java/com/mojang/datafixers/util/Either.java
|
2020-04-17 05:47:15 +02:00
|
|
|
@@ -22,7 +22,7 @@ public abstract class Either<L, R> implements App<Either.Mu<R>, L> {
|
2020-04-13 00:31:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static final class Left<L, R> extends Either<L, R> {
|
|
|
|
- private final L value;
|
2020-04-17 05:47:15 +02:00
|
|
|
+ private final L value; private Optional<L> valueOptional; // Paper - reduce the optional allocation...
|
2020-04-13 00:31:14 +02:00
|
|
|
|
|
|
|
public Left(final L value) {
|
2020-04-17 05:47:15 +02:00
|
|
|
this.value = value;
|
2020-04-13 00:31:14 +02:00
|
|
|
@@ -51,7 +51,7 @@ public abstract class Either<L, R> implements App<Either.Mu<R>, L> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Optional<L> left() {
|
|
|
|
- return Optional.of(value);
|
2020-04-17 05:47:15 +02:00
|
|
|
+ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - reduce the optional allocation...
|
2020-04-13 00:31:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-17 05:47:15 +02:00
|
|
|
@@ -83,7 +83,7 @@ public abstract class Either<L, R> implements App<Either.Mu<R>, L> {
|
2020-04-13 00:31:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static final class Right<L, R> extends Either<L, R> {
|
|
|
|
- private final R value;
|
2020-04-17 05:47:15 +02:00
|
|
|
+ private final R value; private Optional<R> valueOptional; // Paper - reduce the optional allocation...
|
2020-04-13 00:31:14 +02:00
|
|
|
|
|
|
|
public Right(final R value) {
|
2020-04-17 05:47:15 +02:00
|
|
|
this.value = value;
|
2020-04-13 00:31:14 +02:00
|
|
|
@@ -117,7 +117,7 @@ public abstract class Either<L, R> implements App<Either.Mu<R>, L> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Optional<R> right() {
|
|
|
|
- return Optional.of(value);
|
2020-04-17 05:47:15 +02:00
|
|
|
+ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - reduce the optional allocation...
|
2020-04-13 00:31:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
--
|
2020-04-17 05:47:15 +02:00
|
|
|
2.26.0
|
2020-04-13 00:31:14 +02:00
|
|
|
|