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

Don't use Array.Reverse in ImmutableArray<T>.Builder.Reverse #2354

Merged
merged 1 commit into from
Jul 14, 2015
Merged
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,21 @@ public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T> e
/// </summary>
public void Reverse()
{
Array.Reverse(_elements, 0, _count);
// The non-generic Array.Reverse is not used because it does not perform
// well for non-primitive value types.
// If/when a generic Array.Reverse<T> becomes available, the below code
// can be deleted and replaced with a call to Array.Reverse<T>.
int i = 0;
int j = _count - 1;
T[] array = _elements;
while (i < j)
{
T temp = array[i];
array[i] = array[j];
array[j] = temp;
i++;
j--;
}
}

/// <summary>
Expand Down