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

Commit 626649a

Browse files
committed
Merge pull request #2853 from mellinoe/revert-range-optimization
Revert range optimization
2 parents c2aadf2 + 1445591 commit 626649a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/System.Linq/src/System/Linq/Enumerable.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,7 @@ public static IEnumerable<int> Range(int start, int count)
14721472

14731473
private static IEnumerable<int> RangeIterator(int start, int count)
14741474
{
1475-
for (int end = start + count; start < end; start++)
1476-
yield return start;
1475+
for (int i = 0; i < count; i++) yield return start + i;
14771476
}
14781477

14791478
public static IEnumerable<TResult> Repeat<TResult>(TResult element, int count)

src/System.Linq/tests/RangeTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,18 @@ public void Range_GetEnumeratorReturnUniqueInstances()
9292
Assert.NotSame(enum1, enum2);
9393
}
9494
}
95+
96+
[Fact]
97+
public void Range_ToInt32MaxValue()
98+
{
99+
int from = Int32.MaxValue - 3;
100+
int count = 4;
101+
var rangeEnumerable = Enumerable.Range(from, count);
102+
103+
Assert.Equal(count, rangeEnumerable.Count());
104+
105+
int[] expected = { Int32.MaxValue - 3, Int32.MaxValue - 2, Int32.MaxValue - 1, Int32.MaxValue };
106+
Assert.Equal(expected, rangeEnumerable);
107+
}
95108
}
96109
}

0 commit comments

Comments
 (0)