-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Remove a couple LINQ usages in Microsoft.Extensions #47873
Conversation
Tagging subscribers to this area: @maryamariyan Issue DetailsNote that this was the only usage of [MemoryDiagnoser]
public class JoinBenchmark
{
private const string NullValue = "(null)";
private static IEnumerable s_Enumerable = Enumerable.Range(1, 10);
[Benchmark]
public string OldWay()
{
return string.Join(", ", s_Enumerable.Cast<object>().Select(o => o ?? NullValue));
}
[Benchmark]
public string NewWay()
{
var vsb = new ValueStringBuilder(stackalloc char[256]);
bool first = true;
foreach (object e in s_Enumerable)
{
if (!first)
{
vsb.Append(", ");
}
vsb.Append(e != null ? e.ToString() : NullValue);
first = false;
}
return vsb.ToString();
}
}
|
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs
Outdated
Show resolved
Hide resolved
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.
LGTM, Aside from the error:
src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlStreamConfigurationProvider.cs(76,88): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'Stack<string>' does not contain a definition for 'Reverse' and no accessible extension method 'Reverse' accepting a first argument of type 'Stack<string>' could be found (are you missing a using directive or an assembly reference?)
Hello @eerhardt! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Note that this was the only usage of
Enumerable.Cast
in a Blazor WASM default app. So this allows for that method to be trimmed. It is also faster and allocates less according to this benchmark: