Eliminate `ToArray` bounds checks (#81001)
authorxtqqczze <45661989+xtqqczze@users.noreply.github.com>
Mon, 23 Jan 2023 02:02:15 +0000 (02:02 +0000)
committerGitHub <noreply@github.com>
Mon, 23 Jan 2023 02:02:15 +0000 (21:02 -0500)
* Remove `RangeIterator.ToArray` bounds check

https://github.com/dotnet/runtime/pull/80633#discussion_r1082720454

* Eliminate additional `ToArray` bounds checks

src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.SpeedOpt.cs
src/libraries/System.Linq/src/System/Linq/Partition.SpeedOpt.cs
src/libraries/System.Linq/src/System/Linq/Range.SpeedOpt.cs
src/libraries/System.Linq/src/System/Linq/Select.SpeedOpt.cs

index 6ea4b069a1e9ae8b8e060b15985f74f55550057a..c8861e176f03b055eb47e7d8db7b222e6c44eb18 100644 (file)
@@ -21,7 +21,7 @@ namespace System.Linq
 
             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]];
             }
index c46465f82547b3b38aeb82187a6d82b71d487a2b..8555fa1582d298ac850345f5f7e706204ddcddf1 100644 (file)
@@ -254,7 +254,7 @@ namespace System.Linq
                 }
 
                 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];
                 }
index dba2dbb7ec39eb07085008d3f9e6a4d73acfc8ca..6704eef5dedc290cb4db1fa2e6972fbf19427064 100644 (file)
@@ -18,7 +18,7 @@ namespace System.Linq
             {
                 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;
index 8ca02c76b08df2c5b13595b46b68a6d0abf5d468..76ee67b2dcbdb7d6a909c725a34302b20aa1760b 100644 (file)
@@ -789,7 +789,7 @@ namespace System.Linq
                 }
 
                 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]);
                 }