Switch from trove to fastutil collections (#4933)
This commit is contained in:
parent
6367c15d32
commit
539626727c
3 changed files with 30 additions and 25 deletions
|
@ -20,17 +20,18 @@
|
|||
package net.minecraftforge.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import gnu.trove.map.hash.THashMap;
|
||||
|
||||
import net.minecraft.advancements.critereon.ItemPredicate;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
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
|
||||
{
|
||||
|
|
|
@ -23,7 +23,9 @@ import java.util.Map;
|
|||
|
||||
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.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelManager;
|
||||
|
@ -36,8 +38,8 @@ import net.minecraftforge.registries.IRegistryDelegate;
|
|||
*/
|
||||
public class ItemModelMesherForge extends ItemModelMesher
|
||||
{
|
||||
Map<IRegistryDelegate<Item>, TIntObjectHashMap<ModelResourceLocation>> locations = Maps.newHashMap();
|
||||
Map<IRegistryDelegate<Item>, TIntObjectHashMap<IBakedModel>> models = Maps.newHashMap();
|
||||
final Map<IRegistryDelegate<Item>, Int2ObjectMap<ModelResourceLocation>> locations = Maps.newHashMap();
|
||||
final Map<IRegistryDelegate<Item>, Int2ObjectMap<IBakedModel>> models = Maps.newHashMap();
|
||||
|
||||
public ItemModelMesherForge(ModelManager manager)
|
||||
{
|
||||
|
@ -47,7 +49,7 @@ public class ItemModelMesherForge extends ItemModelMesher
|
|||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -55,16 +57,16 @@ public class ItemModelMesherForge extends ItemModelMesher
|
|||
public void register(Item item, int meta, ModelResourceLocation location)
|
||||
{
|
||||
IRegistryDelegate<Item> key = item.delegate;
|
||||
TIntObjectHashMap<ModelResourceLocation> locs = locations.get(key);
|
||||
TIntObjectHashMap<IBakedModel> mods = models.get(key);
|
||||
Int2ObjectMap<ModelResourceLocation> locs = locations.get(key);
|
||||
Int2ObjectMap<IBakedModel> mods = models.get(key);
|
||||
if (locs == null)
|
||||
{
|
||||
locs = new TIntObjectHashMap<ModelResourceLocation>();
|
||||
locs = new Int2ObjectOpenHashMap<>();
|
||||
locations.put(key, locs);
|
||||
}
|
||||
if (mods == null)
|
||||
{
|
||||
mods = new TIntObjectHashMap<IBakedModel>();
|
||||
mods = new Int2ObjectOpenHashMap<>();
|
||||
models.put(key, mods);
|
||||
}
|
||||
locs.put(meta, location);
|
||||
|
@ -75,24 +77,22 @@ public class ItemModelMesherForge extends ItemModelMesher
|
|||
public void rebuildCache()
|
||||
{
|
||||
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)
|
||||
{
|
||||
mods.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mods = new TIntObjectHashMap<IBakedModel>();
|
||||
mods = new Int2ObjectOpenHashMap<>();
|
||||
models.put(e.getKey(), mods);
|
||||
}
|
||||
final TIntObjectHashMap<IBakedModel> map = mods;
|
||||
e.getValue().forEachEntry((meta, location) ->
|
||||
{
|
||||
map.put(meta, manager.getModel(location));
|
||||
return true;
|
||||
});
|
||||
final Int2ObjectMap<IBakedModel> map = mods;
|
||||
e.getValue().int2ObjectEntrySet().forEach(entry ->
|
||||
map.put(entry.getIntKey(), manager.getModel(entry.getValue()))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
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.Unpooled;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
|
@ -31,14 +29,20 @@ import io.netty.util.AttributeKey;
|
|||
import java.lang.ref.WeakReference;
|
||||
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.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
|
||||
|
||||
@Sharable
|
||||
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>>();
|
||||
public abstract class FMLIndexedMessageToMessageCodec<A> extends MessageToMessageCodec<FMLProxyPacket, A>
|
||||
{
|
||||
private final Byte2ObjectMap<Class<? extends A>> discriminators = new Byte2ObjectOpenHashMap<>();
|
||||
private final Object2ByteMap<Class<? extends A>> types = new Object2ByteOpenHashMap<>();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
byte discriminator = types.get(clazz);
|
||||
byte discriminator = types.getByte(clazz);
|
||||
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
|
||||
buffer.writeByte(discriminator);
|
||||
encodeInto(ctx, msg, buffer);
|
||||
|
|
Loading…
Reference in a new issue