I dedicate this to Billy, the one and true dolphin rider

Fixes a data fixer bug
This commit is contained in:
Aikar 2018-09-17 00:41:20 -04:00
parent 9860c9c694
commit e1056b7187

View File

@ -1,4 +1,4 @@
From a694ddcd284ff29b441f5fc14a37b13f3f24fa73 Mon Sep 17 00:00:00 2001 From a0647a441898664025560ad39980647620736867 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co> From: Aikar <aikar@aikar.co>
Date: Mon, 3 Sep 2018 22:18:38 -0400 Date: Mon, 3 Sep 2018 22:18:38 -0400
Subject: [PATCH] Fix concurrency and performance issues in DataFixers Subject: [PATCH] Fix concurrency and performance issues in DataFixers
@ -24,7 +24,7 @@ Additionally, many of the containsKey/get/put style operations were
also a concurrency risk, resulting in multiple computation/insertions. also a concurrency risk, resulting in multiple computation/insertions.
diff --git a/src/main/java/com/mojang/datafixers/DataFixerUpper.java b/src/main/java/com/mojang/datafixers/DataFixerUpper.java diff --git a/src/main/java/com/mojang/datafixers/DataFixerUpper.java b/src/main/java/com/mojang/datafixers/DataFixerUpper.java
index fb2c380f8a..a4922a35a2 100644 index fb2c380f8..a4922a35a 100644
--- a/src/main/java/com/mojang/datafixers/DataFixerUpper.java --- a/src/main/java/com/mojang/datafixers/DataFixerUpper.java
+++ b/src/main/java/com/mojang/datafixers/DataFixerUpper.java +++ b/src/main/java/com/mojang/datafixers/DataFixerUpper.java
@@ -65,7 +65,7 @@ public class DataFixerUpper implements DataFixer { @@ -65,7 +65,7 @@ public class DataFixerUpper implements DataFixer {
@ -58,7 +58,7 @@ index fb2c380f8a..a4922a35a2 100644
protected IntSortedSet fixerVersions() { protected IntSortedSet fixerVersions() {
diff --git a/src/main/java/com/mojang/datafixers/NamedChoiceFinder.java b/src/main/java/com/mojang/datafixers/NamedChoiceFinder.java diff --git a/src/main/java/com/mojang/datafixers/NamedChoiceFinder.java b/src/main/java/com/mojang/datafixers/NamedChoiceFinder.java
index 2c259d74e9..17481fb6e6 100644 index 2c259d74e..17481fb6e 100644
--- a/src/main/java/com/mojang/datafixers/NamedChoiceFinder.java --- a/src/main/java/com/mojang/datafixers/NamedChoiceFinder.java
+++ b/src/main/java/com/mojang/datafixers/NamedChoiceFinder.java +++ b/src/main/java/com/mojang/datafixers/NamedChoiceFinder.java
@@ -71,8 +71,10 @@ final class NamedChoiceFinder<FT> implements OpticFinder<FT> { @@ -71,8 +71,10 @@ final class NamedChoiceFinder<FT> implements OpticFinder<FT> {
@ -75,7 +75,7 @@ index 2c259d74e9..17481fb6e6 100644
return Either.right(new Type.FieldNotFoundException(String.format("Type error for choice type \"%s\": expected type: %s, actual type: %s)", name, targetType, elementType))); return Either.right(new Type.FieldNotFoundException(String.format("Type error for choice type \"%s\": expected type: %s, actual type: %s)", name, targetType, elementType)));
} }
diff --git a/src/main/java/com/mojang/datafixers/functions/PointFree.java b/src/main/java/com/mojang/datafixers/functions/PointFree.java diff --git a/src/main/java/com/mojang/datafixers/functions/PointFree.java b/src/main/java/com/mojang/datafixers/functions/PointFree.java
index 0d88490f77..028942b8ea 100644 index 0d88490f7..028942b8e 100644
--- a/src/main/java/com/mojang/datafixers/functions/PointFree.java --- a/src/main/java/com/mojang/datafixers/functions/PointFree.java
+++ b/src/main/java/com/mojang/datafixers/functions/PointFree.java +++ b/src/main/java/com/mojang/datafixers/functions/PointFree.java
@@ -14,7 +14,7 @@ public abstract class PointFree<T> { @@ -14,7 +14,7 @@ public abstract class PointFree<T> {
@ -88,7 +88,7 @@ index 0d88490f77..028942b8ea 100644
initialized = true; initialized = true;
value = eval(); value = eval();
diff --git a/src/main/java/com/mojang/datafixers/schemas/Schema.java b/src/main/java/com/mojang/datafixers/schemas/Schema.java diff --git a/src/main/java/com/mojang/datafixers/schemas/Schema.java b/src/main/java/com/mojang/datafixers/schemas/Schema.java
index 7c67d989e0..f1fd694b06 100644 index 7c67d989e..7faca88a8 100644
--- a/src/main/java/com/mojang/datafixers/schemas/Schema.java --- a/src/main/java/com/mojang/datafixers/schemas/Schema.java
+++ b/src/main/java/com/mojang/datafixers/schemas/Schema.java +++ b/src/main/java/com/mojang/datafixers/schemas/Schema.java
@@ -20,8 +20,8 @@ import java.util.function.Function; @@ -20,8 +20,8 @@ import java.util.function.Function;
@ -153,23 +153,7 @@ index 7c67d989e0..f1fd694b06 100644
} }
return getTemplate(name); return getTemplate(name);
} }
@@ -101,10 +109,13 @@ public class Schema { @@ -138,9 +146,10 @@ public class Schema {
public Type<?> getChoiceType(final DSL.TypeReference type, final String choiceName) {
final TaggedChoice.TaggedChoiceType<?> choiceType = findChoiceType(type);
- if (!choiceType.types().containsKey(choiceName)) {
+ // Paper start - performance and concurrency - don't use containsKey
+ Type<?> result = choiceType.types().get(choiceName);
+ if (result == null) {
throw new IllegalArgumentException("Data fixer not registered for: " + choiceName + " in " + type.typeName());
}
- return choiceType.types().get(choiceName);
+ return result;
+ // Paper end
}
public TaggedChoice.TaggedChoiceType<?> findChoiceType(final DSL.TypeReference type) {
@@ -138,9 +149,10 @@ public class Schema {
public void registerType(final boolean recursive, final DSL.TypeReference type, final Supplier<TypeTemplate> template) { public void registerType(final boolean recursive, final DSL.TypeReference type, final Supplier<TypeTemplate> template) {
TYPE_TEMPLATES.put(type.typeName(), template); TYPE_TEMPLATES.put(type.typeName(), template);
// TODO: calculate recursiveness instead of hardcoding // TODO: calculate recursiveness instead of hardcoding
@ -182,7 +166,7 @@ index 7c67d989e0..f1fd694b06 100644
public int getVersionKey() { public int getVersionKey() {
diff --git a/src/main/java/com/mojang/datafixers/types/DynamicOps.java b/src/main/java/com/mojang/datafixers/types/DynamicOps.java diff --git a/src/main/java/com/mojang/datafixers/types/DynamicOps.java b/src/main/java/com/mojang/datafixers/types/DynamicOps.java
index 3c76929f24..f21531b3cd 100644 index 3c76929f2..f21531b3c 100644
--- a/src/main/java/com/mojang/datafixers/types/DynamicOps.java --- a/src/main/java/com/mojang/datafixers/types/DynamicOps.java
+++ b/src/main/java/com/mojang/datafixers/types/DynamicOps.java +++ b/src/main/java/com/mojang/datafixers/types/DynamicOps.java
@@ -151,10 +151,10 @@ public interface DynamicOps<T> { @@ -151,10 +151,10 @@ public interface DynamicOps<T> {
@ -201,7 +185,7 @@ index 3c76929f24..f21531b3cd 100644
} }
diff --git a/src/main/java/com/mojang/datafixers/types/Type.java b/src/main/java/com/mojang/datafixers/types/Type.java diff --git a/src/main/java/com/mojang/datafixers/types/Type.java b/src/main/java/com/mojang/datafixers/types/Type.java
index a80e3fee91..2d5bae7a37 100644 index a80e3fee9..2d5bae7a3 100644
--- a/src/main/java/com/mojang/datafixers/types/Type.java --- a/src/main/java/com/mojang/datafixers/types/Type.java
+++ b/src/main/java/com/mojang/datafixers/types/Type.java +++ b/src/main/java/com/mojang/datafixers/types/Type.java
@@ -27,8 +27,10 @@ import javax.annotation.Nullable; @@ -27,8 +27,10 @@ import javax.annotation.Nullable;
@ -254,7 +238,7 @@ index a80e3fee91..2d5bae7a37 100644
public <FT, FR> Type<?> getSetType(final OpticFinder<FT> optic, final Type<FR> newType) { public <FT, FR> Type<?> getSetType(final OpticFinder<FT> optic, final Type<FR> newType) {
diff --git a/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java b/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java diff --git a/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java b/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java
index 4a1f906837..93c2f565fd 100644 index 4a1f90683..93c2f565f 100644
--- a/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java --- a/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java
+++ b/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java +++ b/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java
@@ -32,7 +32,7 @@ public final class RecursiveTypeFamily implements TypeFamily { @@ -32,7 +32,7 @@ public final class RecursiveTypeFamily implements TypeFamily {
@ -267,7 +251,7 @@ index 4a1f906837..93c2f565fd 100644
public RecursiveTypeFamily(final String name, final TypeTemplate template) { public RecursiveTypeFamily(final String name, final TypeTemplate template) {
diff --git a/src/main/java/com/mojang/datafixers/types/templates/Tag.java b/src/main/java/com/mojang/datafixers/types/templates/Tag.java diff --git a/src/main/java/com/mojang/datafixers/types/templates/Tag.java b/src/main/java/com/mojang/datafixers/types/templates/Tag.java
index ece3fb5f88..396637bbd1 100644 index ece3fb5f8..396637bbd 100644
--- a/src/main/java/com/mojang/datafixers/types/templates/Tag.java --- a/src/main/java/com/mojang/datafixers/types/templates/Tag.java
+++ b/src/main/java/com/mojang/datafixers/types/templates/Tag.java +++ b/src/main/java/com/mojang/datafixers/types/templates/Tag.java
@@ -173,8 +173,10 @@ public final class Tag implements TypeTemplate { @@ -173,8 +173,10 @@ public final class Tag implements TypeTemplate {
@ -284,7 +268,7 @@ index ece3fb5f88..396637bbd1 100644
if (value.isPresent()) { if (value.isPresent()) {
return Pair.of(ops.createMap(map.get().entrySet().stream().filter(e -> !Objects.equals(e.getKey(), nameObject)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))), value); return Pair.of(ops.createMap(map.get().entrySet().stream().filter(e -> !Objects.equals(e.getKey(), nameObject)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))), value);
diff --git a/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java b/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java diff --git a/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java b/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java
index e6dd31233a..77d64362b1 100644 index e6dd31233..77d64362b 100644
--- a/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java --- a/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java
+++ b/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java +++ b/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java
@@ -187,17 +187,25 @@ public final class TaggedChoice<K> implements TypeTemplate { @@ -187,17 +187,25 @@ public final class TaggedChoice<K> implements TypeTemplate {
@ -337,5 +321,5 @@ index e6dd31233a..77d64362b1 100644
} }
-- --
2.19.0 2.18.0