refactor(DebugTreeBuilder): DRY BuildAttributeTree via WalkBranches; guard empty NativeSourceCanonicalName

This commit is contained in:
Joseph Doherty
2026-06-17 15:18:09 -04:00
parent 5f387ef3e3
commit c1e786e3fc
@@ -49,33 +49,13 @@ public static class DebugTreeBuilder
}
var segments = attr.AttributeName.Split(Separator);
// Walk/create branch nodes for every segment except the last; the last
// 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
var parent = WalkBranches(segments, segments.Length - 1, roots, branchByKey);
parent.Add(new DebugTreeNode
{
Key = attr.AttributeName,
Segment = segments[^1],
Attribute = attr,
};
currentLevel.Add(leaf);
});
}
SortAndRollUp(roots);
@@ -175,6 +155,8 @@ public static class DebugTreeBuilder
List<DebugTreeNode> roots,
Dictionary<string, DebugTreeNode> branchByKey)
{
if (string.IsNullOrEmpty(alarm.NativeSourceCanonicalName)) return;
var canonical = alarm.NativeSourceCanonicalName;
var segments = canonical.Split(Separator);