Skip to content

Commit 640c344

Browse files
szuendDream-Master
authored andcommitted
cleanup: Skip unused string concatenation (#43)
`updateEntity` in `LogisticsTileGenericPipe` currently creates a debug string that goes unused in normal release builds. We can skip allocating temporary `StringBuilder` instances by checking the DEBUG flag directly. Normally we'd use a format string with an additional varargs argument, but the `add(Super)TraceInformation` methods already use a varargs parameter to pass nested `Infos`. This is the pragmatic, cheap way to remove the calls from the hot path. (cherry picked from commit 23f83a5)
1 parent 6d51566 commit 640c344

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/main/java/logisticspipes/pipes/basic/LogisticsTileGenericPipe.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,11 @@ public void onChunkUnload() {
165165

166166
@Override
167167
public void updateEntity() {
168-
Info superDebug = StackTraceUtil.addSuperTraceInformation("Time: " + getWorld().getWorldTime());
169-
Info debug = StackTraceUtil.addTraceInformation("(" + getX() + ", " + getY() + ", " + getZ() + ")", superDebug);
168+
Info debug = StackTraceUtil.DUMMY_INFO;
169+
if (LPConstants.DEBUG) {
170+
Info superDebug = StackTraceUtil.addSuperTraceInformation("Time: " + getWorld().getWorldTime());
171+
debug = StackTraceUtil.addTraceInformation("(" + getX() + ", " + getY() + ", " + getZ() + ")", superDebug);
172+
}
170173
if (sendInitPacket && MainProxy.isServer(getWorldObj())) {
171174
sendInitPacket = false;
172175
getRenderController().sendInit();

src/main/java/logisticspipes/utils/StackTraceUtil.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public abstract static class Info {
1818
public abstract void end();
1919
}
2020

21-
private static final Info dummyInfo = new Info() {
21+
public static final Info DUMMY_INFO = new Info() {
2222

2323
@Override
2424
public void end() {}
@@ -30,7 +30,7 @@ private static LinkedList<Pair<StackTraceElement, String>> getList() {
3030

3131
public static Info addTraceInformation(final String information, Info... infos) {
3232
if (!LPConstants.DEBUG) {
33-
return dummyInfo;
33+
return DUMMY_INFO;
3434
}
3535
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
3636
final StackTraceElement calledFrom = trace[2];
@@ -39,7 +39,7 @@ public static Info addTraceInformation(final String information, Info... infos)
3939

4040
public static Info addSuperTraceInformation(final String information, Info... infos) {
4141
if (!LPConstants.DEBUG) {
42-
return dummyInfo;
42+
return DUMMY_INFO;
4343
}
4444
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
4545
final StackTraceElement calledFrom = trace[3];

0 commit comments

Comments
 (0)