Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit caaab8a

Browse files
authored
Simplify SelectArrayIterator method (#85695)
1 parent 29d8a16 commit caaab8a

File tree

1 file changed

+8
-6
lines changed
  • src/libraries/System.Linq/src/System/Linq

1 file changed

+8
-6
lines changed

src/libraries/System.Linq/src/System/Linq/Select.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,17 @@ public SelectArrayIterator(TSource[] source, Func<TSource, TResult> selector)
178178

179179
public override bool MoveNext()
180180
{
181-
if (_state < 1 | _state == _source.Length + 1)
181+
TSource[] source = _source;
182+
int index = _state - 1;
183+
if ((uint)index < (uint)source.Length)
182184
{
183-
Dispose();
184-
return false;
185+
_state++;
186+
_current = _selector(source[index]);
187+
return true;
185188
}
186189

187-
int index = _state++ - 1;
188-
_current = _selector(_source[index]);
189-
return true;
190+
Dispose();
191+
return false;
190192
}
191193

192194
public override IEnumerable<TResult2> Select<TResult2>(Func<TResult, TResult2> selector) =>

0 commit comments

Comments
 (0)