aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0369-Reduce-Either-Optional-allocation.patch
blob: 1833cacdfe14214176e107c1e4d0ed1b9c6ec747 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
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 de524d485fada3c3cca8c2fe6c63db0e0b33dad8..6eb0c94965a6e96ec8ae112125e98c6c4809805b 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<L, R> implements App<Either.Mu<R>, L> {
     }
 
     private static final class Left<L, R> extends Either<L, R> {
-        private final L value;
+        private final L value; private Optional<L> valueOptional; // Paper - reduce the optional allocation...
 
         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);
+            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<L, R> implements App<Either.Mu<R>, L> {
     }
 
     private static final class Right<L, R> extends Either<L, R> {
-        private final R value;
+        private final R value; private Optional<R> valueOptional; // Paper - reduce the optional allocation...
 
         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);
+            return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - reduce the optional allocation...
         }
 
         @Override