refactor(DebugTreeBuilder): DRY BuildAttributeTree via WalkBranches; guard empty NativeSourceCanonicalName
This commit is contained in:
+5
-23
@@ -49,33 +49,13 @@ public static class DebugTreeBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
var segments = attr.AttributeName.Split(Separator);
|
var segments = attr.AttributeName.Split(Separator);
|
||||||
|
var parent = WalkBranches(segments, segments.Length - 1, roots, branchByKey);
|
||||||
// Walk/create branch nodes for every segment except the last; the last
|
parent.Add(new DebugTreeNode
|
||||||
// segment becomes the leaf carrying the attribute event.
|
|
||||||
List<DebugTreeNode> currentLevel = roots;
|
|
||||||
string prefix = string.Empty;
|
|
||||||
|
|
||||||
for (var i = 0; i < segments.Length - 1; i++)
|
|
||||||
{
|
|
||||||
prefix = prefix.Length == 0 ? segments[i] : prefix + Separator + segments[i];
|
|
||||||
|
|
||||||
if (!branchByKey.TryGetValue(prefix, out var branch))
|
|
||||||
{
|
|
||||||
branch = new DebugTreeNode { Key = prefix, Segment = segments[i] };
|
|
||||||
branchByKey[prefix] = branch;
|
|
||||||
currentLevel.Add(branch);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentLevel = branch.Children;
|
|
||||||
}
|
|
||||||
|
|
||||||
var leaf = new DebugTreeNode
|
|
||||||
{
|
{
|
||||||
Key = attr.AttributeName,
|
Key = attr.AttributeName,
|
||||||
Segment = segments[^1],
|
Segment = segments[^1],
|
||||||
Attribute = attr,
|
Attribute = attr,
|
||||||
};
|
});
|
||||||
currentLevel.Add(leaf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SortAndRollUp(roots);
|
SortAndRollUp(roots);
|
||||||
@@ -175,6 +155,8 @@ public static class DebugTreeBuilder
|
|||||||
List<DebugTreeNode> roots,
|
List<DebugTreeNode> roots,
|
||||||
Dictionary<string, DebugTreeNode> branchByKey)
|
Dictionary<string, DebugTreeNode> branchByKey)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(alarm.NativeSourceCanonicalName)) return;
|
||||||
|
|
||||||
var canonical = alarm.NativeSourceCanonicalName;
|
var canonical = alarm.NativeSourceCanonicalName;
|
||||||
var segments = canonical.Split(Separator);
|
var segments = canonical.Split(Separator);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user