-
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
Provide overloads to avoid unnecessary boxing #71894
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,6 +276,26 @@ public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this Imm | |
return builder.ToImmutableAndFree(); | ||
} | ||
|
||
/// <summary> | ||
/// Maps and flattens a subset of immutable array to another immutable array. | ||
/// </summary> | ||
/// <typeparam name="TItem">Type of the source array items</typeparam> | ||
/// <typeparam name="TResult">Type of the transformed array items</typeparam> | ||
/// <param name="array">The array to transform</param> | ||
/// <param name="selector">A transform function to apply to each element.</param> | ||
/// <returns>If the array's length is 0, this will return an empty immutable array.</returns> | ||
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this ImmutableArray<TItem> array, Func<TItem, ImmutableArray<TResult>> selector) | ||
{ | ||
if (array.Length == 0) | ||
return ImmutableArray<TResult>.Empty; | ||
|
||
var builder = ArrayBuilder<TResult>.GetInstance(); | ||
foreach (var item in array) | ||
builder.AddRange(selector(item)); | ||
|
||
return builder.ToImmutableAndFree(); | ||
} | ||
|
||
/// <summary> | ||
/// Maps and flattens a subset of immutable array to another immutable array. | ||
/// </summary> | ||
|
@@ -288,17 +308,37 @@ public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this Imm | |
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this ImmutableArray<TItem> array, Func<TItem, bool> predicate, Func<TItem, IEnumerable<TResult>> selector) | ||
{ | ||
if (array.Length == 0) | ||
{ | ||
return ImmutableArray<TResult>.Empty; | ||
|
||
var builder = ArrayBuilder<TResult>.GetInstance(); | ||
foreach (var item in array) | ||
{ | ||
if (predicate(item)) | ||
builder.AddRange(selector(item)); | ||
} | ||
|
||
return builder.ToImmutableAndFree(); | ||
} | ||
|
||
/// <summary> | ||
/// Maps and flattens a subset of immutable array to another immutable array. | ||
/// </summary> | ||
/// <typeparam name="TItem">Type of the source array items</typeparam> | ||
/// <typeparam name="TResult">Type of the transformed array items</typeparam> | ||
/// <param name="array">The array to transform</param> | ||
/// <param name="predicate">The condition to use for filtering the array content.</param> | ||
/// <param name="selector">A transform function to apply to each element that is not filtered out by <paramref name="predicate"/>.</param> | ||
/// <returns>If the items's length is 0, this will return an empty immutable array.</returns> | ||
public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this ImmutableArray<TItem> array, Func<TItem, bool> predicate, Func<TItem, ImmutableArray<TResult>> selector) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 There were two callers of the previous overload prior to this change. After this change, there is one caller of the previous overload, and one caller of the new overload. |
||
{ | ||
if (array.Length == 0) | ||
return ImmutableArray<TResult>.Empty; | ||
|
||
var builder = ArrayBuilder<TResult>.GetInstance(); | ||
foreach (var item in array) | ||
{ | ||
if (predicate(item)) | ||
{ | ||
builder.AddRange(selector(item)); | ||
} | ||
} | ||
|
||
return builder.ToImmutableAndFree(); | ||
|
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.
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.
📝 There were 16 callers of the previous overload prior to this change. After this change, there are 3 callers of the previous overload, and 13 callers of the new overload.