2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2022-09-26 10:02:51 +02:00
|
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
2021-06-11 14:02:28 +02:00
|
|
|
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
|
2024-01-21 12:11:43 +01:00
|
|
|
index de524d485fada3c3cca8c2fe6c63db0e0b33dad8..a51e8e3eafff17f4f2ff790bf96a2f0e89abca2a 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/com/mojang/datafixers/util/Either.java
|
|
|
|
+++ b/src/main/java/com/mojang/datafixers/util/Either.java
|
|
|
|
@@ -22,7 +22,7 @@ public abstract class Either<L, R> implements App<Either.Mu<R>, L> {
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final class Left<L, R> extends Either<L, R> {
|
|
|
|
- private final L value;
|
2024-01-21 12:11:43 +01:00
|
|
|
+ private final L value; private Optional<L> valueOptional; // Paper - Perf: Reduce Either Optional allocation
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
public Left(final L value) {
|
|
|
|
this.value = value;
|
|
|
|
@@ -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);
|
2024-01-21 12:11:43 +01:00
|
|
|
+ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - Perf: Reduce Either Optional allocation
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@@ -83,7 +83,7 @@ public abstract class Either<L, R> implements App<Either.Mu<R>, L> {
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final class Right<L, R> extends Either<L, R> {
|
|
|
|
- private final R value;
|
2024-01-21 12:11:43 +01:00
|
|
|
+ private final R value; private Optional<R> valueOptional; // Paper - Perf: Reduce Either Optional allocation
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
public Right(final R value) {
|
|
|
|
this.value = value;
|
|
|
|
@@ -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);
|
2024-01-21 12:11:43 +01:00
|
|
|
+ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - Perf: Reduce Either Optional allocation
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|