From ea4d78c0f2600e7593175ba7f3d35493e6c84869 Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 16 Nov 2022 21:25:17 +0000 Subject: Remove recursive calls in class source visitor --- .../spark/common/sampler/source/ClassSourceLookup.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'spark-common/src/main/java/me') diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/source/ClassSourceLookup.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/source/ClassSourceLookup.java index 66b41d2..ab63c00 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/source/ClassSourceLookup.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/source/ClassSourceLookup.java @@ -36,10 +36,12 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.security.CodeSource; import java.security.ProtectionDomain; +import java.util.ArrayDeque; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.Queue; import java.util.function.Function; import java.util.stream.Collectors; @@ -265,8 +267,10 @@ public interface ClassSourceLookup { @Override public void visit(ThreadNode node) { - for (StackTraceNode child : node.getChildren()) { - visitStackNode(child); + Queue queue = new ArrayDeque<>(node.getChildren()); + for (StackTraceNode n = queue.poll(); n != null; n = queue.poll()) { + visitStackNode(n); + queue.addAll(n.getChildren()); } } @@ -288,11 +292,6 @@ public interface ClassSourceLookup { MethodCallByLine methodCall = new MethodCallByLine(node.getClassName(), node.getMethodName(), node.getLineNumber()); this.lineSources.computeIfAbsent(methodCall, this.lookup::identify); } - - // recursively - for (StackTraceNode child : node.getChildren()) { - visitStackNode(child); - } } @Override -- cgit