Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup ShellDescripterFeaturesManager #12310

Merged
merged 2 commits into from
Sep 2, 2022

Conversation

MikeAlhayek
Copy link
Member

@jtkech here is a PR to clean up the ShellDescriptorFeaturesManager after PR #12281 was merged

.Where(f => shellDescriptor.Features.Any(sf => sf.Id == f.Id))
.ToHashSet();
Copy link
Member

Choose a reason for hiding this comment

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

You can remove this .ToHashSet().

Hmm but replace it with a .ToArray() so that it is not lazy evaluated twice below.

then I will merge

Copy link
Member Author

@MikeAlhayek MikeAlhayek Sep 2, 2022

Choose a reason for hiding this comment

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

@jtkech I made the change. Any reason why ToArray() instead of ToHashSet()? Either way I made the changes. Its ready to be merged. Maybe ToList() https://stackoverflow.com/questions/1105990/is-it-better-to-call-tolist-or-toarray-in-linq-queries

Copy link
Member

@jtkech jtkech Sep 2, 2022

Choose a reason for hiding this comment

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

Okay thanks

Both prevent re-evaluation, ToHashSet is useful when we then use Add/Remove and it will compare to existing items in an optimized way, works with strings and classes that are IEquatable otherwise the comparizon is by ref (object pointers are compared) which works too if a given featureInfo is always related to the same object instance, which I think it is the case here as they are always returned from the extensionManager that doesn' clone items collection but ...

@jtkech jtkech merged commit 149ab6c into OrchardCMS:main Sep 2, 2022
@MikeAlhayek MikeAlhayek deleted the CleanupEnabledByDependencyOnly branch September 2, 2022 04:35
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