Commits

Parker Hawke authored and md_5 committed b7e9f1c8b9f
SPIGOT-7146: Reduce use of Material switch in ItemMeta

The Java compiler expands switch statements into a synthetic method that generates an int array with the enum's ordinal. For small enums this is fine, but with an enum as large as Material, this can add over one hundred thousand additional bytes of data. This unnecessarily increases CraftBukkit's overall file size by over 2MB. Where possible, simple conditions are returned. In cases where more than 2 constants are referenced, a HashSet is used (as opposed to an EnumSet which generates a large backing array into memory).
No tags

src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmorStand.java

Modified
1 1 package org.bukkit.craftbukkit.inventory;
2 2
3 3 import com.google.common.collect.ImmutableMap.Builder;
4 4 import java.util.Map;
5 5 import net.minecraft.nbt.NBTBase;
6 6 import net.minecraft.nbt.NBTTagCompound;
7 7 import org.bukkit.Material;
8 8 import org.bukkit.configuration.serialization.DelegateDeserialization;
9 -import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey;
10 9
11 10 @DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
12 11 public class CraftMetaArmorStand extends CraftMetaItem {
13 12
14 13 static final ItemMetaKey ENTITY_TAG = new ItemMetaKey("EntityTag", "entity-tag");
15 14 NBTTagCompound entityTag;
16 15
17 16 CraftMetaArmorStand(CraftMetaItem meta) {
18 17 super(meta);
19 18
57 56 void applyToItem(NBTTagCompound tag) {
58 57 super.applyToItem(tag);
59 58
60 59 if (entityTag != null) {
61 60 tag.put(ENTITY_TAG.NBT, entityTag);
62 61 }
63 62 }
64 63
65 64 @Override
66 65 boolean applicableTo(Material type) {
67 - switch (type) {
68 - case ARMOR_STAND:
69 - return true;
70 - default:
71 - return false;
72 - }
66 + return type == Material.ARMOR_STAND;
73 67 }
74 68
75 69 @Override
76 70 boolean isEmpty() {
77 71 return super.isEmpty() && isArmorStandEmpty();
78 72 }
79 73
80 74 boolean isArmorStandEmpty() {
81 75 return !(entityTag != null);
82 76 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut