Hi,
There is a difference in the implementation of OrderedEnumerable, which affects
the way how keySelector is threated.
Consider the following example:
[Test]
public void OrderByNonDeterministic()
{
var values = "abcd".ToCharArray();
int key = values.Count();
values = values.OrderBy(_ => key--).ToArray();
Assert.AreEqual("dcba", new String(values));
Assert.AreEqual(0, key, "Key for every element is computed only once");
}
keySelector is evaluated only once for each element in System.Core, and then
resulting key array is sorted.
As an opposite in LinqBridge keySelector is computed for every two elements
being compared. So it produces different result. Even for deterministic
keySelector this can hurt performance.
According to the documentation of OrderBy there are no limitations to the
keySelector function, except that Comparer<TKey>.Default must exist for key
values being returned, if such comparer isn't provided for OrderBy.
Original issue reported on code.google.com by mrdont@mail.ru on 31 May 2011 at 9:49
Original issue reported on code.google.com by
mrdont@mail.ru
on 31 May 2011 at 9:49