Merge pull request #74 from kashike/feature/noop

feat: Re-use a NOOP tracer
This commit is contained in:
Chris Vest 2021-05-28 16:28:16 +02:00 committed by GitHub
commit a6b4aeaaba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,7 +27,7 @@ import java.util.stream.Stream;
public abstract class LifecycleTracer { public abstract class LifecycleTracer {
public static LifecycleTracer get() { public static LifecycleTracer get() {
if (Trace.TRACE_LIFECYCLE_DEPTH == 0) { if (Trace.TRACE_LIFECYCLE_DEPTH == 0) {
return new NoOpTracer(); return NoOpTracer.INSTANCE;
} }
StackTracer stackTracer = new StackTracer(); StackTracer stackTracer = new StackTracer();
stackTracer.addTrace(StackTracer.WALKER.walk(new Trace("allocate", 0))); stackTracer.addTrace(StackTracer.WALKER.walk(new Trace("allocate", 0)));
@ -45,6 +45,8 @@ public abstract class LifecycleTracer {
public abstract <E extends Throwable> E attachTrace(E throwable); public abstract <E extends Throwable> E attachTrace(E throwable);
private static final class NoOpTracer extends LifecycleTracer { private static final class NoOpTracer extends LifecycleTracer {
private static final NoOpTracer INSTANCE = new NoOpTracer();
@Override @Override
public void acquire(int acquires) { public void acquire(int acquires) {
} }