Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Add Span<T>.Sort(...) by changing Array.Sort internals to be Span based #24419

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8e1dce1
Try changing Array.Sort to work on Spans first...
nietras May 4, 2019
7bf009b
change Array public back, but add sort to memory extensions
nietras May 6, 2019
d7d9713
remove line
nietras May 6, 2019
c9d5906
revert BinarySearch
nietras May 6, 2019
05c1a04
fix binarysearch in interface
nietras May 6, 2019
6079482
Add dummy TrySZSort overload
nietras May 6, 2019
ddd36d7
Cleanup Sort Span public methods a bit
nietras May 7, 2019
056709d
Convert Array to Span via Unsafe
nietras May 7, 2019
6a31593
Remove not need TrySZSort overload
nietras May 7, 2019
ad27730
Change Span Sort API to follow approved API (does not compile)
nietras May 8, 2019
66f88b9
Initial TComparer support
nietras May 8, 2019
178b1ed
ArraySortHelper<TKey, TValue> TComparer
nietras May 8, 2019
a0ef68e
comment
nietras May 8, 2019
7700cb1
Remove AggressiveInlining attributes
nietras May 8, 2019
d0740c9
Revert "ArraySortHelper<TKey, TValue> TComparer"
nietras May 9, 2019
1b3fe24
Undo last TComparer stuff
nietras May 15, 2019
ff2d950
AggressiveInlining SwapIfGreaterWithItems
nietras May 25, 2019
22ccaea
`in` trial (easy to do so testing it)
nietras May 25, 2019
e497563
Remove AggresiveInlining
nietras May 25, 2019
c6affb2
avoiding lo and hi
nietras May 25, 2019
9e600d4
Add AggressiveInlining to Swap(
nietras May 26, 2019
7a047a8
AggressiveInlining
nietras May 26, 2019
5c1cc96
Swap( remove `in`
nietras May 26, 2019
2a81a55
Revert "avoiding lo and hi"
nietras May 26, 2019
4cac6a9
remove AggresiveInlining for Swap(
nietras May 26, 2019
8d68c43
Revert "remove AggresiveInlining for Swap("
nietras May 26, 2019
a6a553c
Remove TODO comments
nietras May 26, 2019
7f6296b
cleanup to limit changes
nietras Jun 1, 2019
f8a35ee
readd MemoryExtensions span methods
nietras Jun 1, 2019
74cafec
remove some debug.asserts
nietras Jun 1, 2019
992ef7a
remove more debug asserts
nietras Jun 1, 2019
9c56769
cleanup CoreCLR file
nietras Jun 1, 2019
32bc189
remove comment
nietras Jun 1, 2019
e352bc3
Remove comment
nietras Jun 1, 2019
cdda4ba
fix nullable
nietras Jun 2, 2019
7de0096
fix nullable
nietras Jun 2, 2019
f1031b8
remove unnecessary changes, fix nullables ? (master seems to have cha…
nietras Jun 2, 2019
93648bc
merge master
nietras Jun 2, 2019
66044d7
Fix TODO-NULLABLE
nietras Jun 2, 2019
1c1e877
empty line after throw
nietras Jun 2, 2019
478632e
Add "using System.Runtime.CompilerServices;"
nietras Jun 2, 2019
11dd34a
Merge branch 'master' into ntr/span-sort-2
nietras Jun 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/System.Private.CoreLib/shared/System/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,8 +1544,8 @@ public static void Sort<T>(T[] array, int index, int length, System.Collections.
}
}
#endif

ArraySortHelper<T>.Default.Sort(array, index, length, comparer);
var span = new Span<T>(ref Unsafe.As<byte, T>(ref array.GetRawArrayData()), array.Length);
ArraySortHelper<T>.Default.Sort(span, index, length, comparer!);
}
}

Expand Down Expand Up @@ -1578,7 +1578,9 @@ public static void Sort<TKey, TValue>(TKey[] keys, TValue[]? items, int index, i
return;
}

ArraySortHelper<TKey, TValue>.Default.Sort(keys, items, index, length, comparer);
var spanKeys = new Span<TKey>(ref Unsafe.As<byte, TKey>(ref keys.GetRawArrayData()), keys.Length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be GetRawSzArrayData()

var spanItems = new Span<TValue>(ref Unsafe.As<byte, TValue>(ref items!.GetRawArrayData()), items!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
ArraySortHelper<TKey, TValue>.Default.Sort(spanKeys, spanItems, index, length, comparer);
}
}

Expand All @@ -1594,7 +1596,8 @@ public static void Sort<T>(T[] array, Comparison<T> comparison)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison);
}

ArraySortHelper<T>.Sort(array!, 0, array!.Length, comparison!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
var span = new Span<T>(ref Unsafe.As<byte, T>(ref array!.GetRawArrayData()), array!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
ArraySortHelper<T>.Sort(span, 0, span.Length, comparison!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
}

public static bool TrueForAll<T>(T[] array, Predicate<T> match)
Expand Down
Loading