Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -670,29 +670,10 @@ private readonly ImmutableArray<T> InlineItemsToImmutableArray()
}

public readonly T[] ToArray()
{
if (TryGetBuilder(out var builder))
{
return builder.ToArray();
}

return _inlineCount switch
{
0 => [],
1 => [_element0],
2 => [_element0, _element1],
3 => [_element0, _element1, _element2],
_ => [_element0, _element1, _element2, _element3]
};
}
=> ImmutableCollectionsMarshal.AsArray(ToImmutable()).AssumeNotNull();
Copy link
Contributor

Choose a reason for hiding this comment

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

=> ImmutableCollectionsMarshal.AsArray(ToImmutable()).AssumeNotNull();

Curious why you didn't keep the ToArray* impls and change the ToImmutable* impls to use those instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's simpler this way. ImmutableArray<T>.Builder.DrainToImmutable() returns an ImmutableArray<T> -- there's no DrainToArray(). So, we'd have to unwrap the result in ToArray() and then the ToImmutable() methods would need to re-wrap the array. Seems more awkward that way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Dur, Todd


public T[] ToArrayAndClear()
{
var result = ToArray();
Clear();

return result;
}
=> ImmutableCollectionsMarshal.AsArray(ToImmutableAndClear()).AssumeNotNull();

public void Push(T item)
{
Expand Down
Loading