diff options
author | Lluis Sanchez <llsan@microsoft.com> | 2022-06-16 12:00:49 +0300 |
---|---|---|
committer | Lluis Sanchez <llsan@microsoft.com> | 2022-09-13 20:38:42 +0300 |
commit | 6f0d811b6823b378d1db44f5d2bb6aab7d684a83 (patch) | |
tree | f2b7a60f602acc78db83290c383b2432ce29912a | |
parent | a323ecba60c9285945d33ae26283998f2d70ba63 (diff) |
Use immutable array to track condition dependencies
-rw-r--r-- | Mono.Addins/Mono.Addins/ExtensionContext.cs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Mono.Addins/Mono.Addins/ExtensionContext.cs b/Mono.Addins/Mono.Addins/ExtensionContext.cs index 58a296f..b3205b9 100644 --- a/Mono.Addins/Mono.Addins/ExtensionContext.cs +++ b/Mono.Addins/Mono.Addins/ExtensionContext.cs @@ -277,6 +277,7 @@ namespace Mono.Addins { // We are going to do many changes, to create a builder for the dictionary var dictBuilder = conditionsToNodes.ToBuilder (); + List<(string ConditionId, BaseCondition BoundCondition)> bindings = new (); // Group nodes by the conditions, so that all nodes for a conditions can be processed together @@ -292,20 +293,21 @@ namespace Mono.Addins condition.GetConditionTypes (conditionTypeIds); foreach (string cid in conditionTypeIds) { - // For each condition on which 'condition' depends, register the dependency // so that it if the condition changes, the dependencies are notified - ConditionInfo info = GetOrCreateConditionInfo (transaction, cid, null); - if (info.BoundConditions == null) - info.BoundConditions = new List<BaseCondition> (); - - info.BoundConditions.Add (condition); + bindings.Add ((cid, condition)); } list = ImmutableArray<TreeNode>.Empty; } dictBuilder [condition] = list.AddRange (group.Select (item => item.Node)); } + + foreach (var binding in bindings.GroupBy(b => b.ConditionId, b => b.BoundCondition)) { + ConditionInfo info = GetOrCreateConditionInfo (transaction, binding.Key, null); + info.BoundConditions = info.BoundConditions.AddRange (binding); + } + conditionsToNodes = dictBuilder.ToImmutable (); } @@ -340,8 +342,8 @@ namespace Mono.Addins condition.GetConditionTypes (conditionTypeIds); foreach (string cid in conditionTypeIds) { var info = conditionTypes [cid]; - if (info != null && info.BoundConditions != null) - info.BoundConditions.Remove (condition); + if (info != null) + info.BoundConditions = info.BoundConditions.Remove (condition); } } else dictBuilder [condition] = newList; @@ -1259,7 +1261,7 @@ namespace Mono.Addins class ConditionInfo { public object CondType; - public List<BaseCondition> BoundConditions; + public ImmutableArray<BaseCondition> BoundConditions = ImmutableArray<BaseCondition>.Empty; } |