aboutsummaryrefslogtreecommitdiff
path: root/spark-common
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2022-11-16 21:25:17 +0000
committerLuck <git@lucko.me>2022-11-16 21:25:17 +0000
commitea4d78c0f2600e7593175ba7f3d35493e6c84869 (patch)
tree620e25da39632cf36742b0321c23d86e2cca3020 /spark-common
parent3b0564cc4b259f49a15aa6cdb2c4b8e35f5e26e0 (diff)
downloadspark-ea4d78c0f2600e7593175ba7f3d35493e6c84869.tar.gz
spark-ea4d78c0f2600e7593175ba7f3d35493e6c84869.tar.bz2
spark-ea4d78c0f2600e7593175ba7f3d35493e6c84869.zip
Remove recursive calls in class source visitor
Diffstat (limited to 'spark-common')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/source/ClassSourceLookup.java13
1 files changed, 6 insertions, 7 deletions
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<StackTraceNode> 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