Skip to content

Commit

Permalink
Eliminate ToArray bounds checks (#81001)
Browse files Browse the repository at this point in the history
* Remove `RangeIterator.ToArray` bounds check

#80633 (comment)

* Eliminate additional `ToArray` bounds checks
  • Loading branch information
xtqqczze committed Jan 23, 2023
1 parent 5bd322b commit a272954
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public virtual TElement[] ToArray()

TElement[] array = new TElement[count];
int[] map = SortedMap(buffer);
for (int i = 0; i != array.Length; i++)
for (int i = 0; i < array.Length; i++)
{
array[i] = buffer._items[map[i]];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public TSource[] ToArray()
}

TSource[] array = new TSource[count];
for (int i = 0, curIdx = _minIndexInclusive; i != array.Length; ++i, ++curIdx)
for (int i = 0, curIdx = _minIndexInclusive; i < array.Length; ++i, ++curIdx)
{
array[i] = _source[curIdx];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public int[] ToArray()
{
int[] array = new int[_end - _start];
int cur = _start;
for (int i = 0; i != array.Length; ++i)
for (int i = 0; i < array.Length; ++i)
{
array[i] = cur;
++cur;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ public TResult[] ToArray()
}

TResult[] array = new TResult[count];
for (int i = 0, curIdx = _minIndexInclusive; i != array.Length; ++i, ++curIdx)
for (int i = 0, curIdx = _minIndexInclusive; i < array.Length; ++i, ++curIdx)
{
array[i] = _selector(_source[curIdx]);
}
Expand Down

0 comments on commit a272954

Please sign in to comment.