Delete OrderBy(...).First{OrDefault}(...) optimization (#36643)
authorStephen Toub <stoub@microsoft.com>
Mon, 18 May 2020 15:58:11 +0000 (11:58 -0400)
committerGitHub <noreply@github.com>
Mon, 18 May 2020 15:58:11 +0000 (11:58 -0400)
commite102b34b8415234e41defe7391161ca967f74725
tree916219f619fa559a9964a2a1e9f74cdb67a70537
parent6a0570fe5bed49b7705571f817386a2dc6d4c8ce
Delete OrderBy(...).First{OrDefault}(...) optimization (#36643)

The optimization removes the O(n log n) cost of the OrderBy. But it can result in executing the predicate passed to First{OrDefault} more than in .NET Framework; it would always execute it n times, whereas previously it would execute it <= n times.  Developers have expressed concern about the change, in particular when using a relatively expensive predicate on a relatively short list, or when unadvisedly relying on side-effecting predicates.
src/libraries/System.Linq/src/System/Linq/First.cs
src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.cs
src/libraries/System.Linq/tests/OrderByTests.cs