Switch from trove to fastutil collections (#4933)

This commit is contained in:
Ben Staddon 2018-06-27 19:29:09 +01:00 committed by LexManos
parent 6367c15d32
commit 539626727c
3 changed files with 30 additions and 25 deletions

View file

@ -20,17 +20,18 @@
package net.minecraftforge.advancements.critereon; package net.minecraftforge.advancements.critereon;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import gnu.trove.map.hash.THashMap;
import net.minecraft.advancements.critereon.ItemPredicate; import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
public class ItemPredicates public class ItemPredicates
{ {
private static final Map<ResourceLocation, Function<JsonObject, ItemPredicate>> predicates = new THashMap<>(); private static final Map<ResourceLocation, Function<JsonObject, ItemPredicate>> predicates = new HashMap<>();
static static
{ {

View file

@ -23,7 +23,9 @@ import java.util.Map;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import gnu.trove.map.hash.TIntObjectHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minecraft.client.renderer.ItemModelMesher; import net.minecraft.client.renderer.ItemModelMesher;
import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelManager; import net.minecraft.client.renderer.block.model.ModelManager;
@ -36,8 +38,8 @@ import net.minecraftforge.registries.IRegistryDelegate;
*/ */
public class ItemModelMesherForge extends ItemModelMesher public class ItemModelMesherForge extends ItemModelMesher
{ {
Map<IRegistryDelegate<Item>, TIntObjectHashMap<ModelResourceLocation>> locations = Maps.newHashMap(); final Map<IRegistryDelegate<Item>, Int2ObjectMap<ModelResourceLocation>> locations = Maps.newHashMap();
Map<IRegistryDelegate<Item>, TIntObjectHashMap<IBakedModel>> models = Maps.newHashMap(); final Map<IRegistryDelegate<Item>, Int2ObjectMap<IBakedModel>> models = Maps.newHashMap();
public ItemModelMesherForge(ModelManager manager) public ItemModelMesherForge(ModelManager manager)
{ {
@ -47,7 +49,7 @@ public class ItemModelMesherForge extends ItemModelMesher
@Override @Override
protected IBakedModel getItemModel(Item item, int meta) protected IBakedModel getItemModel(Item item, int meta)
{ {
TIntObjectHashMap<IBakedModel> map = models.get(item.delegate); Int2ObjectMap<IBakedModel> map = models.get(item.delegate);
return map == null ? null : map.get(meta); return map == null ? null : map.get(meta);
} }
@ -55,16 +57,16 @@ public class ItemModelMesherForge extends ItemModelMesher
public void register(Item item, int meta, ModelResourceLocation location) public void register(Item item, int meta, ModelResourceLocation location)
{ {
IRegistryDelegate<Item> key = item.delegate; IRegistryDelegate<Item> key = item.delegate;
TIntObjectHashMap<ModelResourceLocation> locs = locations.get(key); Int2ObjectMap<ModelResourceLocation> locs = locations.get(key);
TIntObjectHashMap<IBakedModel> mods = models.get(key); Int2ObjectMap<IBakedModel> mods = models.get(key);
if (locs == null) if (locs == null)
{ {
locs = new TIntObjectHashMap<ModelResourceLocation>(); locs = new Int2ObjectOpenHashMap<>();
locations.put(key, locs); locations.put(key, locs);
} }
if (mods == null) if (mods == null)
{ {
mods = new TIntObjectHashMap<IBakedModel>(); mods = new Int2ObjectOpenHashMap<>();
models.put(key, mods); models.put(key, mods);
} }
locs.put(meta, location); locs.put(meta, location);
@ -75,24 +77,22 @@ public class ItemModelMesherForge extends ItemModelMesher
public void rebuildCache() public void rebuildCache()
{ {
final ModelManager manager = this.getModelManager(); final ModelManager manager = this.getModelManager();
for (Map.Entry<IRegistryDelegate<Item>, TIntObjectHashMap<ModelResourceLocation>> e : locations.entrySet()) for (Map.Entry<IRegistryDelegate<Item>, Int2ObjectMap<ModelResourceLocation>> e : locations.entrySet())
{ {
TIntObjectHashMap<IBakedModel> mods = models.get(e.getKey()); Int2ObjectMap<IBakedModel> mods = models.get(e.getKey());
if (mods != null) if (mods != null)
{ {
mods.clear(); mods.clear();
} }
else else
{ {
mods = new TIntObjectHashMap<IBakedModel>(); mods = new Int2ObjectOpenHashMap<>();
models.put(e.getKey(), mods); models.put(e.getKey(), mods);
} }
final TIntObjectHashMap<IBakedModel> map = mods; final Int2ObjectMap<IBakedModel> map = mods;
e.getValue().forEachEntry((meta, location) -> e.getValue().int2ObjectEntrySet().forEach(entry ->
{ map.put(entry.getIntKey(), manager.getModel(entry.getValue()))
map.put(meta, manager.getModel(location)); );
return true;
});
} }
} }
} }

View file

@ -19,8 +19,6 @@
package net.minecraftforge.fml.common.network; package net.minecraftforge.fml.common.network;
import gnu.trove.map.hash.TByteObjectHashMap;
import gnu.trove.map.hash.TObjectByteHashMap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
@ -31,14 +29,20 @@ import io.netty.util.AttributeKey;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.List; import java.util.List;
import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap;
import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ByteMap;
import it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.common.FMLLog; import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
@Sharable @Sharable
public abstract class FMLIndexedMessageToMessageCodec<A> extends MessageToMessageCodec<FMLProxyPacket, A> { public abstract class FMLIndexedMessageToMessageCodec<A> extends MessageToMessageCodec<FMLProxyPacket, A>
private TByteObjectHashMap<Class<? extends A>> discriminators = new TByteObjectHashMap<Class<? extends A>>(); {
private TObjectByteHashMap<Class<? extends A>> types = new TObjectByteHashMap<Class<? extends A>>(); private final Byte2ObjectMap<Class<? extends A>> discriminators = new Byte2ObjectOpenHashMap<>();
private final Object2ByteMap<Class<? extends A>> types = new Object2ByteOpenHashMap<>();
/** /**
* Make this accessible to subclasses * Make this accessible to subclasses
@ -71,7 +75,7 @@ public abstract class FMLIndexedMessageToMessageCodec<A> extends MessageToMessag
{ {
throw new RuntimeException("Undefined discriminator for message type " + clazz.getSimpleName() + " in channel " + channel); throw new RuntimeException("Undefined discriminator for message type " + clazz.getSimpleName() + " in channel " + channel);
} }
byte discriminator = types.get(clazz); byte discriminator = types.getByte(clazz);
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
buffer.writeByte(discriminator); buffer.writeByte(discriminator);
encodeInto(ctx, msg, buffer); encodeInto(ctx, msg, buffer);