Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use MethodHandle to prevent autoboxing allocations #47

Merged
merged 3 commits into from
May 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/main/java/logisticspipes/proxy/buildcraft/BCRenderTESR.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package logisticspipes.proxy.buildcraft;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;

import buildcraft.transport.TileGenericPipe;
Expand All @@ -10,32 +12,37 @@

public class BCRenderTESR implements IBCRenderTESR {

private final Method renderGatesWires;
private final Method renderPluggables;
private final MethodHandle renderGatesWires;
private final MethodHandle renderPluggables;

@SneakyThrows(Exception.class)
BCRenderTESR() {
renderGatesWires = PipeRendererTESR.class.getDeclaredMethod(
MethodHandles.Lookup lookup = MethodHandles.lookup();

Method renderGatesWiresMethod = PipeRendererTESR.class.getDeclaredMethod(
"renderGatesWires",
new Class[] { TileGenericPipe.class, double.class, double.class, double.class });
renderGatesWires.setAccessible(true);
renderPluggables = PipeRendererTESR.class.getDeclaredMethod(
renderGatesWiresMethod.setAccessible(true);
renderGatesWires = lookup.unreflect(renderGatesWiresMethod);

Method renderPluggablesMethod = PipeRendererTESR.class.getDeclaredMethod(
"renderPluggables",
new Class[] { TileGenericPipe.class, double.class, double.class, double.class });
renderPluggables.setAccessible(true);
renderPluggablesMethod.setAccessible(true);
renderPluggables = lookup.unreflect(renderPluggablesMethod);
}

@Override
@SneakyThrows(Exception.class)
@SneakyThrows(Throwable.class)
public void renderWires(LogisticsTileGenericPipe pipe, double x, double y, double z) {
TileGenericPipe tgPipe = (TileGenericPipe) pipe.tilePart.getOriginal();
renderGatesWires.invoke(PipeRendererTESR.INSTANCE, tgPipe, x, y, z);
renderGatesWires.invokeExact(PipeRendererTESR.INSTANCE, tgPipe, x, y, z);
}

@Override
@SneakyThrows(Exception.class)
@SneakyThrows(Throwable.class)
public void dynamicRenderPluggables(LogisticsTileGenericPipe pipe, double x, double y, double z) {
TileGenericPipe tgPipe = (TileGenericPipe) pipe.tilePart.getOriginal();
renderPluggables.invoke(PipeRendererTESR.INSTANCE, tgPipe, x, y, z);
renderPluggables.invokeExact(PipeRendererTESR.INSTANCE, tgPipe, x, y, z);
}
}
Loading