From 663c7f09f1aa62d23a9cfad9826a93901969b489 Mon Sep 17 00:00:00 2001 From: Spottedleaf 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 index a90adac7bd7..3f65fe71024 100644 --- 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 implements App, L> { } private static final class Left extends Either { - private final L value; + private final L value; private Optional valueOptional; // Paper - reduce the optional allocation... public Left(final L value) { this.value = value; @@ -51,7 +51,7 @@ public abstract class Either implements App, L> { @Override public Optional left() { - return Optional.of(value); + return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - reduce the optional allocation... } @Override @@ -83,7 +83,7 @@ public abstract class Either implements App, L> { } private static final class Right extends Either { - private final R value; + private final R value; private Optional valueOptional; // Paper - reduce the optional allocation... public Right(final R value) { this.value = value; @@ -117,7 +117,7 @@ public abstract class Either implements App, L> { @Override public Optional right() { - return Optional.of(value); + return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - reduce the optional allocation... } @Override -- 2.26.2