From 14244d2c19f1c0e6f4ff9f312b6e49e5ce7ecfb6 Mon Sep 17 00:00:00 2001 From: tznind Date: Wed, 17 Feb 2021 19:25:33 +0000 Subject: [PATCH] Improved performance of TreeSelection.Contains --- Terminal.Gui/Views/TreeView.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/Views/TreeView.cs b/Terminal.Gui/Views/TreeView.cs index 4acb41dc8..d1526f456 100644 --- a/Terminal.Gui/Views/TreeView.cs +++ b/Terminal.Gui/Views/TreeView.cs @@ -1082,7 +1082,7 @@ namespace Terminal.Gui { public Branch Origin {get;} - private HashSet> alsoIncluded = new HashSet>(); + private HashSet included = new HashSet(); /// /// Creates a new selection between two branches in the tree @@ -1093,6 +1093,8 @@ namespace Terminal.Gui { public TreeSelection(Branch from, int toIndex, Branch[] map ) { Origin = from; + included.Add(Origin.Model); + var oldIdx = Array.IndexOf(map,from); var lowIndex = Math.Min(oldIdx,toIndex); @@ -1100,15 +1102,13 @@ namespace Terminal.Gui { // Select everything between the old and new indexes foreach(var alsoInclude in map.Skip(lowIndex).Take(highIndex-lowIndex)){ - alsoIncluded.Add(alsoInclude); + included.Add(alsoInclude.Model); } } public bool Contains(T model) { - return - Equals(Origin.Model,model) || - alsoIncluded.Any(b=>Equals(b.Model,model)); + return included.Contains(model); } }