mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
Add cache for ASM Event Handler bridge classes, should not need to redefine a class to invoke the same method on different instances.
This commit is contained in:
1 parent
15d158161e
commit
0e571eeb19
1 file changed
+12
-1
@@ -3,12 +3,15 @@ package net.minecraftforge.event;
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
||||
public class ASMEventHandler implements IEventListener
|
||||
{
|
||||
@@ -16,6 +19,7 @@ public class ASMEventHandler implements IEventListener
|
||||
private static final String HANDLER_DESC = Type.getInternalName(IEventListener.class);
|
||||
private static final String HANDLER_FUNC_DESC = Type.getMethodDescriptor(IEventListener.class.getDeclaredMethods()[0]);
|
||||
private static final ASMClassLoader LOADER = new ASMClassLoader();
|
||||
private static final HashMap<Method, Class<?>> cache = Maps.newHashMap();
|
||||
|
||||
private final IEventListener handler;
|
||||
private final ForgeSubscribe subInfo;
|
||||
@@ -44,6 +48,11 @@ public class ASMEventHandler implements IEventListener
|
||||
|
||||
public Class<?> createWrapper(Method callback)
|
||||
{
|
||||
if (cache.containsKey(callback))
|
||||
{
|
||||
return cache.get(callback);
|
||||
}
|
||||
|
||||
ClassWriter cw = new ClassWriter(0);
|
||||
MethodVisitor mv;
|
||||
|
||||
@@ -92,7 +101,9 @@ public class ASMEventHandler implements IEventListener
|
||||
mv.visitEnd();
|
||||
}
|
||||
cw.visitEnd();
|
||||
return LOADER.define(name, cw.toByteArray());
|
||||
Class<?> ret = LOADER.define(name, cw.toByteArray());
|
||||
cache.put(callback, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private String getUniqueName(Method callback)
|
||||
|
||||
Reference in new issue
Block a user