-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Misc improvements of OneOrMany #68948
Conversation
src/Compilers/Core/CodeAnalysisTest/InternalUtilities/OneOrManyTests.cs
Outdated
Show resolved
Hide resolved
this type seems to have a lot of brokennes :'( |
if (many is [var item]) | ||
{ | ||
_one = item; | ||
_many = default; |
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.
I understand this makes the internal invariants of the type a lot simpler but it does mean we essentially introduce allocations for this pattern where before there was no allocation:
var array = ImmutableArray.Create<int>(42);
var oneOrMany = new OneOrMany<int>(array);
// Before no alloc, after allocs
oneOrMany.ToImmutable();
Are we concerned this could regress allocations? Don't have a guid intuition on how common this would be.
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.
Yes, potentially. I don't think it's common since we usually know at creation time that we only have a single element so we wouldn't create that array.
Adds custom debugger display.
Adds
SequenceEqual
and a few convenience helpers.