Code Quality: Reduce redundant SelectedItems updates in SelectionChanged#18495
Open
muko wants to merge 2 commits into
Open
Code Quality: Reduce redundant SelectedItems updates in SelectionChanged#18495muko wants to merge 2 commits into
muko wants to merge 2 commits into
Conversation
workbysaran
reviewed
May 19, 2026
| if (e is not null && e.AddedItems.Count == 0 && e.RemovedItems.Count == 0) | ||
| return; | ||
|
|
||
| var selectedItems = FileList.SelectedItems.Cast<ListedItem>().Where(x => x is not null).ToList(); |
Contributor
There was a problem hiding this comment.
Since BaseGroupableLayoutPage.FileList_SelectionChanged is the base handler all other layouts use, can we move the SequenceEqual check there instead?
Contributor
Author
There was a problem hiding this comment.
The intent is to return early before allocating a new list instance via ToList().
| if (e is null && SelectedItems?.Count == 0) | ||
| return; | ||
|
|
||
| if (e is not null && e.AddedItems.Count == 0 && e.RemovedItems.Count == 0) |
Contributor
There was a problem hiding this comment.
The SequenceEqual check already covers this since it compares the final selection state rather than how it changed. If AddedItems and RemovedItems are both empty, SequenceEqual will return true anyway. Can you clarify why this separate check is needed?
Contributor
Author
There was a problem hiding this comment.
I’ll think about moving it to the base class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolved / Related Issues
When selecting files or folders,
SelectionChangedis raised multiple times even when the actual selection does not change.For example, when opening a folder by double-clicking,
SelectionChangedis fired repeatedly without any real change inSelectedItems.The root cause is that
SelectedItemswas always assigned from a new list instance:Since
ToList()creates a new list instance on every call, the setter was always triggered and caused unnecessary side effects (such as PropertyChanged-driven updates).Steps used to test these changes