Updated InsertItemsRange to simplify the expression and added performance improvement...
authorAndrew Hoefling <andrew@hoeflingsoftware.com>
Wed, 6 Mar 2019 00:00:01 +0000 (19:00 -0500)
committerSantiago Fernandez Madero <safern@microsoft.com>
Fri, 8 Mar 2019 19:20:58 +0000 (11:20 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/dadee3b355c75e33d0c925b27ba3f301d100a51b

src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs

index ea7bcb3..1a83b3f 100644 (file)
@@ -187,11 +187,16 @@ namespace System.Collections.ObjectModel
                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
             }
 
-            int i = 0;
-            foreach (T item in collection)
+            if (GetType() == typeof(Collection<T>) && items is List<T> list)
             {
-                Insert(index + i, item);
-                i++;
+                list.InsertRange(index, collection);
+            }
+            else
+            {
+                foreach (T item in collection)
+                {
+                    InsertItem(index++, item);
+                }
             }
         }