Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public abstract class IEnumerableTest<T>
protected T DefaultValue => default(T);

protected bool MoveNextAtEndThrowsOnModifiedCollection => true;
protected virtual bool CurrentAfterFullEnumerationThrows => true;

protected virtual CollectionOrder CollectionOrder => CollectionOrder.Sequential;

Expand Down Expand Up @@ -352,7 +353,7 @@ public void EnumeratePastEndThenModify()
VerifyModifiedEnumerator(
enumerator,
DefaultValue,
false,
CurrentAfterFullEnumerationThrows,
true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ public ReadOnlyDictionaryOverNonGenericTests()
protected override bool IsGenericCompatibility { get { return false; } }
protected override bool ItemsMustBeUnique { get { return true; } }
protected override bool ItemsMustBeNonNull { get { return true; } }
protected override bool CurrentAfterFullEnumerationThrows { get { return false; } }
protected override object GenerateItem()
{
return new KeyValuePair<string, int>(m_next_item.ToString(), m_next_item++);
Expand Down Expand Up @@ -429,6 +430,7 @@ public ReadOnlyDictionaryTestsStringInt()
protected override bool IsGenericCompatibility { get { return false; } }
protected override bool ItemsMustBeUnique { get { return true; } }
protected override bool ItemsMustBeNonNull { get { return true; } }
protected override bool CurrentAfterFullEnumerationThrows { get { return false; } }
protected override object GenerateItem()
{
return new KeyValuePair<string, int>(m_next_item.ToString(), m_next_item++);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1185,16 +1185,15 @@ public bool TrueForAll(Predicate<T> match)
public struct Enumerator : IEnumerator<T>, IEnumerator
{
private readonly List<T> _list;
private int _index;
private readonly int _version;

private int _index;
private T? _current;

internal Enumerator(List<T> list)
{
_list = list;
_index = 0;
_version = list._version;
_current = default;
}

public void Dispose()
Expand All @@ -1205,24 +1204,20 @@ public bool MoveNext()
{
List<T> localList = _list;

if (_version == localList._version && ((uint)_index < (uint)localList._size))
if (_version != _list._version)
{
_current = localList._items[_index];
_index++;
return true;
ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
}
return MoveNextRare();
}

private bool MoveNextRare()
{
if (_version != _list._version)
if ((uint)_index < (uint)localList._size)
{
ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
_current = localList._items[_index];
_index++;
return true;
}

_index = _list._size + 1;
_current = default;
_index = -1;
return false;
}

Expand All @@ -1232,11 +1227,12 @@ private bool MoveNextRare()
{
get
{
if (_index == 0 || _index == _list._size + 1)
if (_index <= 0)
{
ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
}
return Current;

return _current;
}
}

Expand Down
Loading