From aace4bbfe3d2942644014319f9ea291f512e9a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Standa=20Luke=C5=A1?= Date: Tue, 22 Mar 2022 14:59:48 +0000 Subject: [PATCH] Fix VirtualPropertyGroupDictionary.Clear It was removing properties while it was iterating through the dictionary :| --- .../Binding/VirtualPropertyGroupDictionary.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Framework/Framework/Binding/VirtualPropertyGroupDictionary.cs b/src/Framework/Framework/Binding/VirtualPropertyGroupDictionary.cs index c4d72f73aa..ca121e8bdd 100644 --- a/src/Framework/Framework/Binding/VirtualPropertyGroupDictionary.cs +++ b/src/Framework/Framework/Binding/VirtualPropertyGroupDictionary.cs @@ -246,14 +246,32 @@ public void Add(KeyValuePair item) public void Clear() { + // we want to avoid allocating the list if there is only one property + DotvvmProperty? toRemove = null; + List? toRemoveRest = null; + foreach (var (p, _) in control.properties) { var pg = p as GroupedDotvvmProperty; if (pg != null && pg.PropertyGroup == group) { - control.Properties.Remove(p); + if (toRemove is null) + toRemove = p; + else + { + if (toRemoveRest is null) + toRemoveRest = new List(); + toRemoveRest.Add(p); + } } } + + if (toRemove is {}) + control.Properties.Remove(toRemove); + + if (toRemoveRest is {}) + foreach (var p in toRemoveRest) + control.Properties.Remove(p); } public bool Contains(KeyValuePair item)