cache slow InventoryProperty default keys
import org.spongepowered.api.data.Property;
import org.spongepowered.api.item.inventory.InventoryProperty;
+import java.util.HashMap;
import java.util.Locale;
+import java.util.Map;
import javax.annotation.Nullable;
*/
public abstract class AbstractInventoryProperty<K, V> implements InventoryProperty<K, V> {
+ private static Map<Class<? extends AbstractInventoryProperty>, String> defaultKeys = new HashMap<>();
+
/**
* Operator for comparing to other properties. Operators should always be
* applied by consumers in a &lt;this&gt; &lt;OPERATOR&gt; &lt;other&gt;
@@ -113,7 +117,7 @@ protected AbstractInventoryProperty(@Nullable K key, @Nullable V value, Operator
*/
@SuppressWarnings("unchecked")
protected K getDefaultKey(@Nullable V value) {
- return (K) this.getClass().getSimpleName().toLowerCase(Locale.ENGLISH);
+ return (K) defaultKeys.computeIfAbsent(this.getClass(), k -> this.getClass().getSimpleName().toLowerCase(Locale.ENGLISH));
}
/**
