Fix Dictionary CopyTo regression (#17300)
authorBen Adams <thundercat@illyriad.co.uk>
Wed, 28 Mar 2018 23:11:38 +0000 (00:11 +0100)
committerStephen Toub <stoub@microsoft.com>
Wed, 28 Mar 2018 23:11:38 +0000 (16:11 -0700)
src/mscorlib/shared/System/Collections/Generic/Dictionary.cs
src/mscorlib/shared/System/Collections/Generic/List.cs

index 827cc24..f0e8928 100644 (file)
@@ -315,7 +315,7 @@ namespace System.Collections.Generic
             {
                 if (entries[i].hashCode >= 0)
                 {
-                    array[index + i] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value);
+                    array[index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value);
                 }
             }
         }
@@ -822,7 +822,7 @@ namespace System.Collections.Generic
                 {
                     if (entries[i].hashCode >= 0)
                     {
-                        dictEntryArray[index + i] = new DictionaryEntry(entries[i].key, entries[i].value);
+                        dictEntryArray[index++] = new DictionaryEntry(entries[i].key, entries[i].value);
                     }
                 }
             }
@@ -842,7 +842,7 @@ namespace System.Collections.Generic
                     {
                         if (entries[i].hashCode >= 0)
                         {
-                            objects[index + i] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value);
+                            objects[index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value);
                         }
                     }
                 }
@@ -1210,7 +1210,7 @@ namespace System.Collections.Generic
                 Entry[] entries = _dictionary._entries;
                 for (int i = 0; i < count; i++)
                 {
-                    if (entries[i].hashCode >= 0) array[index + i] = entries[i].key;
+                    if (entries[i].hashCode >= 0) array[index++] = entries[i].key;
                 }
             }
 
@@ -1270,7 +1270,7 @@ namespace System.Collections.Generic
                     {
                         for (int i = 0; i < count; i++)
                         {
-                            if (entries[i].hashCode >= 0) objects[index + i] = entries[i].key;
+                            if (entries[i].hashCode >= 0) objects[index++] = entries[i].key;
                         }
                     }
                     catch (ArrayTypeMismatchException)
@@ -1393,7 +1393,7 @@ namespace System.Collections.Generic
                 Entry[] entries = _dictionary._entries;
                 for (int i = 0; i < count; i++)
                 {
-                    if (entries[i].hashCode >= 0) array[index + i] = entries[i].value;
+                    if (entries[i].hashCode >= 0) array[index++] = entries[i].value;
                 }
             }
 
@@ -1453,7 +1453,7 @@ namespace System.Collections.Generic
                     {
                         for (int i = 0; i < count; i++)
                         {
-                            if (entries[i].hashCode >= 0) objects[index + i] = entries[i].value;
+                            if (entries[i].hashCode >= 0) objects[index++] = entries[i].value;
                         }
                     }
                     catch (ArrayTypeMismatchException)
index a5cbf12..6b9f9b4 100644 (file)
@@ -163,12 +163,12 @@ namespace System.Collections.Generic
 
             set
             {
-                _version++;
                 if ((uint)index >= (uint)_size)
                 {
                     ThrowHelper.ThrowArgumentOutOfRange_IndexException();
                 }
                 _items[index] = value;
+                _version++;
             }
         }