From 37e09caac57c57226d6bbe2e0974d1a7e30e0b99 Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 16 Apr 2020 14:50:44 +0100 Subject: [PATCH] Slightly optimize SimpleMetaValueSelector by only invoking the selection strategy if there is a selection to be made --- .../common/cacheddata/type/SimpleMetaValueSelector.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/SimpleMetaValueSelector.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/SimpleMetaValueSelector.java index 8f4585e8b..2aa48cdfd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/SimpleMetaValueSelector.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/SimpleMetaValueSelector.java @@ -43,7 +43,14 @@ public class SimpleMetaValueSelector implements MetaValueSelector { @Override public @NonNull String selectValue(@NonNull String key, @NonNull List values) { - return this.strategies.getOrDefault(key, this.defaultStrategy).select(values); + switch (values.size()) { + case 0: + throw new IllegalArgumentException("values is empty"); + case 1: + return values.get(0); + default: + return this.strategies.getOrDefault(key, this.defaultStrategy).select(values); + } } public enum Strategy {