From 3971a5969f4ade15a038c2f6637065aa9421cd31 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 25 Mar 2018 21:33:14 +0100 Subject: [PATCH] Revert behaviour change version moves --- .../shared/System/Collections/Generic/Dictionary.cs | 4 ++-- src/mscorlib/shared/System/Collections/Generic/List.cs | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs b/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs index 2a88ca1b1de6..827cc24ac247 100644 --- a/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs +++ b/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs @@ -672,7 +672,6 @@ public bool Remove(TKey key) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); } - _version++; if (_buckets != null) { int hashCode = (_comparer?.GetHashCode(key) ?? key.GetHashCode()) & 0x7FFFFFFF; @@ -708,6 +707,7 @@ public bool Remove(TKey key) } _freeList = i; _freeCount++; + _version++; return true; } @@ -728,7 +728,6 @@ public bool Remove(TKey key, out TValue value) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); } - _version++; if (_buckets != null) { int hashCode = (_comparer?.GetHashCode(key) ?? key.GetHashCode()) & 0x7FFFFFFF; @@ -767,6 +766,7 @@ public bool Remove(TKey key, out TValue value) } _freeList = i; _freeCount++; + _version++; return true; } diff --git a/src/mscorlib/shared/System/Collections/Generic/List.cs b/src/mscorlib/shared/System/Collections/Generic/List.cs index 80b8b0c970d6..a5cbf12a658b 100644 --- a/src/mscorlib/shared/System/Collections/Generic/List.cs +++ b/src/mscorlib/shared/System/Collections/Generic/List.cs @@ -676,7 +676,6 @@ public int IndexOf(T item, int index, int count) // public void Insert(int index, T item) { - _version++; // Note that insertions at the end are legal. if ((uint)index > (uint)_size) { @@ -689,6 +688,7 @@ public void Insert(int index, T item) } _items[index] = item; _size++; + _version++; } void IList.Insert(int index, object item) @@ -868,7 +868,6 @@ void IList.Remove(object item) // The complexity is O(n). public int RemoveAll(Predicate match) { - _version++; if (match == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); @@ -900,6 +899,7 @@ public int RemoveAll(Predicate match) int result = _size - freeIndex; _size = freeIndex; + _version++; return result; } @@ -947,12 +947,13 @@ public void RemoveRange(int index, int count) { Array.Copy(_items, index + count, _items, index, _size - index); } + + _version++; if (RuntimeHelpers.IsReferenceOrContainsReferences()) { Array.Clear(_items, _size, count); } } - _version++; } // Reverses the elements in this list. @@ -1091,10 +1092,10 @@ public bool TrueForAll(Predicate match) private void AddEnumerable(IEnumerable enumerable) { - _version++; // Even if the enumerable has no items, we can update _version. Debug.Assert(enumerable != null); Debug.Assert(!(enumerable is ICollection), "We should have optimized for this beforehand."); + _version++; // Even if the enumerable has no items, we can update _version. using (IEnumerator en = enumerable.GetEnumerator()) {