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

Commit 82f8331

Browse files
committed
Merge pull request #2665 from James-Ko/range
Small optimization for Range
2 parents adc46ae + 31599c5 commit 82f8331

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public IEnumerable<TResult> Select<TResult>(Func<TSource, TResult> selector)
136136
//
137137
// Normally, this happens when you chain two consecutive Select<,>. There may be
138138
// some clever way to handle that second generic parameter within the limitations of the
139-
// static type system but it's a lot simpler just to break the chain by inserting
139+
// static type system but it's a lot simpler just to break the chain by inserting
140140
// a dummy Where(x => y) in the middle.
141141
//
142142
return new WhereEnumerableIterator<TSource>(this, x => true).SelectImpl<TResult>(selector);
@@ -1436,7 +1436,8 @@ public static IEnumerable<int> Range(int start, int count)
14361436

14371437
private static IEnumerable<int> RangeIterator(int start, int count)
14381438
{
1439-
for (int i = 0; i < count; i++) yield return start + i;
1439+
for (int end = start + count; start < end; start++)
1440+
yield return start;
14401441
}
14411442

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

0 commit comments

Comments
 (0)