Skip to content

Commit 5aea3ec

Browse files
committed
Optimized DataTree node resolution
GetFullPath didn't get much benefit, but more performance is always welcome.
1 parent 4b0d3d6 commit 5aea3ec

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

External/Plugins/FlashDebugger/Controls/DataTreeControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void NameNodeTextBox_LabelChanged(object sender, LabelEventArgs e)
159159
if (box.Parent.CurrentNode == null) return;
160160
DataNode node = box.Parent.CurrentNode.Tag as DataNode;
161161

162-
if (e.NewLabel.Trim() == "")
162+
if (e.NewLabel.Trim() == "" || e.NewLabel.Trim() == TextHelper.GetString("Label.AddExpression"))
163163
{
164164
node.Text = e.OldLabel != "" ? e.OldLabel : TextHelper.GetString("Label.AddExpression");
165165
return;
@@ -522,7 +522,7 @@ private void RestoreExpanded(Collection<Node> nodes)
522522
if (nodes == null) return;
523523
foreach (Node node in nodes)
524524
{
525-
if (state.Expanded.Contains(_model.GetFullPath(node)))
525+
if (!node.IsLeaf && state.Expanded.Contains(_model.GetFullPath(node)))
526526
{
527527
Tree.FindNode(_model.GetPath(node)).Expand();
528528
RestoreExpanded(node.Nodes);

External/Plugins/FlashDebugger/Controls/DataTreeModel.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Aga.Controls.Tree;
1+
using System.Text;
2+
using Aga.Controls.Tree;
23

34
namespace FlashDebugger.Controls
45
{
@@ -9,39 +10,41 @@ public class DataTreeModel : TreeModel
910
public string GetFullPath(Node node)
1011
{
1112
if (node == Root) return string.Empty;
12-
else
13+
14+
var path = new StringBuilder();
15+
while (node != Root && node != null)
1316
{
14-
string path = string.Empty;
15-
while (node != Root && node != null)
16-
{
17-
path = string.Format("{0}.{1}", node.Text, path);
18-
node = node.Parent;
19-
}
20-
return path.TrimEnd(chTrims);
17+
path.Insert(0, node.Text).Insert(node.Text.Length, ".");
18+
node = node.Parent;
2119
}
20+
if (path.Length > 0) path.Length--;
21+
22+
return path.ToString();
2223
}
2324

2425
public Node FindNode(string path)
2526
{
26-
if (path == string.Empty) return Root;
27-
else return FindNode(Root, path);
27+
if (string.IsNullOrEmpty(path)) return Root;
28+
return FindNode(Root, path, new StringBuilder());
2829
}
2930

30-
private Node FindNode(Node root, string path)
31+
private Node FindNode(Node root, string path, StringBuilder nodePath)
3132
{
33+
int initialLength = nodePath.Length;
3234
foreach (Node node in root.Nodes)
3335
{
34-
// TODO: We could optimize some more here, we don't need to get the full path
35-
string nodePath = GetFullPath(node);
36-
if (path == nodePath) return node;
37-
if (path.StartsWith(nodePath))
36+
nodePath = nodePath.Append(node.Text);
37+
if (path == nodePath.ToString()) return node;
38+
nodePath.Append(".");
39+
if (path.StartsWith(nodePath.ToString()))
3840
{
3941
if (node.Nodes.Count > 0)
4042
{
41-
Node tmp = FindNode(node, path);
43+
Node tmp = FindNode(node, path, nodePath);
4244
if (tmp != null) return tmp;
4345
}
4446
}
47+
else nodePath.Length = initialLength;
4548
}
4649
return null;
4750
}

External/Plugins/FlashDebugger/Controls/WatchUI.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public void UpdateElements()
8383
{
8484
treeControl.Tree.BeginUpdate();
8585
treeControl.SaveState();
86+
8687
treeControl.Nodes.Clear();
8788
foreach (String item in watches)
8889
{

0 commit comments

Comments
 (0)