-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Remove IList.Contains use from OfType #119600
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes the optimization in OfType<T>().Contains() that delegated to IList.Contains() to fix correctness issues when the source contains items that compare equal but are not of the target type, and to handle multidimensional arrays properly.
- Removes the
IList.Contains()delegation optimization fromOfTypeIterator<TResult>.Contains() - Adds comprehensive test coverage for multidimensional arrays with
OfType() - Adds test coverage for the type filtering behavior when objects compare equal but are different types
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Linq/src/System/Linq/OfType.SpeedOpt.cs | Removes IList.Contains optimization and adds detailed comment explaining why direct iteration is necessary |
| src/libraries/System.Linq/tests/OfTypeTests.cs | Adds tests for multidimensional arrays and type filtering behavior with custom equality |
|
Tagging subscribers to this area: @dotnet/area-system-linq |
|
/backport to release/10.0 |
|
Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17660453305 |
Fixes #119569