From bd349ac4a3838746f123aaa0dc899e7b75eea490 Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 13 Dec 2019 14:02:31 +0000 Subject: [PATCH] Use standard (not Identity) HashMaps for OptionKeys and NodeMetadataKeys --- .../main/java/net/luckperms/api/query/SimpleOptionKey.java | 4 +++- .../me/lucko/luckperms/common/node/AbstractNodeBuilder.java | 3 ++- .../luckperms/common/query/QueryOptionsBuilderImpl.java | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/net/luckperms/api/query/SimpleOptionKey.java b/api/src/main/java/net/luckperms/api/query/SimpleOptionKey.java index 097a43179..1a5dccb67 100644 --- a/api/src/main/java/net/luckperms/api/query/SimpleOptionKey.java +++ b/api/src/main/java/net/luckperms/api/query/SimpleOptionKey.java @@ -32,10 +32,12 @@ import java.util.Objects; final class SimpleOptionKey implements OptionKey { private final String name; private final Class type; + private final int hashCode; SimpleOptionKey(String name, Class type) { this.name = name.toLowerCase(); this.type = type; + this.hashCode = Objects.hash(this.name, this.type); // cache hashcode } @Override @@ -64,6 +66,6 @@ final class SimpleOptionKey implements OptionKey { @Override public int hashCode() { - return Objects.hash(this.name, this.type); + return this.hashCode; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/node/AbstractNodeBuilder.java b/common/src/main/java/me/lucko/luckperms/common/node/AbstractNodeBuilder.java index 81d0cbaef..96b2c13ec 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/AbstractNodeBuilder.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/AbstractNodeBuilder.java @@ -39,6 +39,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; +import java.util.HashMap; import java.util.IdentityHashMap; import java.util.Map; import java.util.Objects; @@ -61,7 +62,7 @@ public abstract class AbstractNodeBuilder, B extends this.value = value; this.expireAt = expireAt; this.context = new ImmutableContextSetImpl.BuilderImpl().addAll(context); - this.metadata = new IdentityHashMap<>(metadata); + this.metadata = new HashMap<>(metadata); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/query/QueryOptionsBuilderImpl.java b/common/src/main/java/me/lucko/luckperms/common/query/QueryOptionsBuilderImpl.java index 64d80afc1..2f0eebc8d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/query/QueryOptionsBuilderImpl.java +++ b/common/src/main/java/me/lucko/luckperms/common/query/QueryOptionsBuilderImpl.java @@ -38,7 +38,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.EnumSet; -import java.util.IdentityHashMap; +import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -124,9 +124,9 @@ public class QueryOptionsBuilderImpl implements QueryOptions.Builder { if (this.options == null || this.copyOptions) { if (this.options != null) { - this.options = new IdentityHashMap<>(this.options); + this.options = new HashMap<>(this.options); } else { - this.options = new IdentityHashMap<>(); + this.options = new HashMap<>(); } this.copyOptions = false; }