Minor bug fix for Array.Sort: Replace keys.Length with length for FloorLog2PlusOne#16002
Conversation
| if (length < 2) | ||
| return; | ||
|
|
||
| IntroSort(keys, left, length + left - 1, 2 * IntrospectiveSortUtilities.FloorLog2PlusOne(keys.Length), comparer); |
There was a problem hiding this comment.
The same bug seems to be in the non-generic sort version in Array.cs. Could you please fix it there as well?
|
LGTM. thanks a lot for the help @nietras |
…orLog2PlusOne (dotnet#16002) * replace keys.Length with length for FloorLog2PlusOne * fix non-generic sort
|
@jkotas is this fix not part of .NET Core 2.1 Preview1? |
|
@jkotas I should note that the reason I ask is because this does have an impact on the result of the sorting of keys with items (values). Since |
|
This fix is not in .NET Core 2.1 preview1 |
During my work with implementing https://github.com/dotnet/corefx/issues/15329 I found an issue with the C# implementation of Array.Sort.
The wrong length is used for the introspective sort depth limit. It uses the whole arrays length instead of the sub view input.
The actual impact for this is hard to determine, but worst case the depth limit is way too high causing degenerate cases not to fall back to heap sort, when it should. As far as I can tell.
cc: @jkotas