OperableHierarchicalCollection - in 'collapse_row,' only call '_sync' if refresh is deferred

This commit is contained in:
John Colvin committed 2019-04-22 22:25:18 -05:00
1 parent 0d94377f36
commit 33140fa901
1 file changed
+18 -14
@@ -77,22 +77,26 @@ namespace bts.collections {
public void collapse_row(TKey key) {
_tree.collapse_row(key);
_sync();
/// Rather than calling <see cref="sync"/>, 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 <see cref="sync"/>, 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));
}
}