Skip to content

Conversation

ThereGoesMySanity
Copy link

I was noticing very poor performance when trying to implement a "Select All" button for lists of ~5000 elements. Refactoring SelectedItems to use a HashSet provides major performance improvements. Also added a SelectMany method that only updates the property once.

var newSelections = virtualListView?.SelectedItems ?? Array.Empty<ItemPosition>();
ISet<ItemPosition> newSelections = virtualListView?.SelectedItems ?? new HashSet<ItemPosition>();

if (virtualListView.SelectionMode == SelectionMode.None)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a small refactoring suggestion, as i wonder if this needs to be checked for null as well? I Mean when virtualListView is null, it throws a NullReferenceException.
So in the current state when we have a virtualListView of null we have a new HashSet on Line 107 but cannot continue, as it should throw an exception on Line 109/111

Suggested change
if (virtualListView.SelectionMode == SelectionMode.None)
if (virtualListView?.SelectionMode == SelectionMode.None)

if (virtualListView.SelectionMode == SelectionMode.None)
newSelections = Array.Empty<ItemPosition>();
newSelections = new HashSet<ItemPosition>();
else if (virtualListView.SelectionMode == SelectionMode.Single && newSelections.Count > 1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the same problem here

Suggested change
else if (virtualListView.SelectionMode == SelectionMode.Single && newSelections.Count > 1)
else if (virtualListView?.SelectionMode == SelectionMode.Single && newSelections.Count > 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants