From 33140fa901f8c3ccc9c65f8845dc4e2460ffa4f3 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Mon, 22 Apr 2019 22:25:18 -0500 Subject: [PATCH] OperableHierarchicalCollection - in 'collapse_row,' only call '_sync' if refresh is deferred --- .../OperableHierarchicalCollection.cs | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/client/spark_core/Collections/Operable/Hierarchical/OperableHierarchicalCollection.cs b/src/client/spark_core/Collections/Operable/Hierarchical/OperableHierarchicalCollection.cs index 27bdb176c..5a0f22db2 100644 --- a/src/client/spark_core/Collections/Operable/Hierarchical/OperableHierarchicalCollection.cs +++ b/src/client/spark_core/Collections/Operable/Hierarchical/OperableHierarchicalCollection.cs @@ -77,22 +77,26 @@ namespace bts.collections { public void collapse_row(TKey key) { _tree.collapse_row(key); - _sync(); - /// Rather than calling , this optimization leverages the fact that the relative order of the rows has not changed, and the only mutation will be removing a single continuous block of rows. - using (var en = _tree.rows.GetEnumerator()) { - int pos = 0; - while (en.MoveNext()) { - if (!pos_matches()) { - // found the beginning of the remove-block - remove each row until the keys match again - do _remove_at(pos); - while (!pos_matches()); + if (_refresh.is_execution_deferred) { + // Do NOT attempt any optimizations (this collection was already out of sync with the tree). + _sync(); + } else { + /// Rather than calling , this optimization leverages the fact that the relative order of the rows has not changed, and the only mutation will be removing a single continuous block of rows. + using (var en = _tree.rows.GetEnumerator()) { + int pos = 0; + while (en.MoveNext()) { + if (!pos_matches()) { + // found the beginning of the remove-block - remove each row until the keys match again + do _remove_at(pos); + while (!pos_matches()); + } + pos++; } - pos++; + while (pos < Count) + _remove_at(pos); + bool pos_matches() => + _key(this[pos].value).Equals(_key(en.Current.value)); } - while (pos < Count) - _remove_at(pos); - bool pos_matches() => - _key(this[pos].value).Equals(_key(en.Current.value)); } }