Optimized RemoveItemsRange to call the list.RemoveRange if the items is of type List<T>
authorAndrew Hoefling <andrew@hoeflingsoftware.com>
Thu, 7 Mar 2019 23:08:22 +0000 (18:08 -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/d29c78bbbcb033f7d189bcc162e580176160a1c9

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

index 40268ea..40c8ed8 100644 (file)
@@ -220,11 +220,18 @@ namespace System.Collections.ObjectModel
             if (index > items.Count - count)
             {
                 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
-            }            
+            }
 
-            for (int i = 0; i < count; i++)
+            if (GetType() == typeof(Collection<T>) && items is List<T> list)
             {
-                RemoveItem(index);
+                list.RemoveRange(index, count);
+            }
+            else
+            {
+                for (int i = 0; i < count; i++)
+                {
+                    RemoveItem(index);
+                }
             }
         }