- Notifications
You must be signed in to change notification settings - Fork5.1k
Special case arrays in Enumerable.DefaultIfEmpty#98963
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Arrays are fixed-length, and DefaultIfEmpty only applies special behaviors on top of the input enumerable if it's empty. Thus, we can special-case arrays, such that if the input is a non-empty array, we just return the original input rather than wrapping it in a new enumerable.
ghost commentedFeb 27, 2024
Tagging subscribers to this area: @dotnet/area-system-linq Issue DetailsArrays are fixed-length, and DefaultIfEmpty only applies special behaviors on top of the input enumerable if it's empty. Thus, we can special-case arrays, such that if the input is a non-empty array, we just return the original input rather than wrapping it in a new enumerable. usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);[MemoryDiagnoser(false)][HideColumns("Job","Error","StdDev","Median","RatioSD")]publicpartialclassTests{privateint[]_data=Enumerable.Range(0,1000).ToArray();[Benchmark]publicdoubleAverage()=>_data.DefaultIfEmpty().Average();}
|
Arrays are fixed-length, and DefaultIfEmpty only applies special behaviors on top of the input enumerable if it's empty. Thus, we can special-case arrays, such that if the input is a non-empty array, we just return the original input rather than wrapping it in a new enumerable.