diff options
author | Andrew Hoefling <andrew@hoeflingsoftware.com> | 2019-03-05 19:00:01 -0500 |
---|---|---|
committer | Santiago Fernandez Madero <safern@microsoft.com> | 2019-03-08 11:20:58 -0800 |
commit | dadee3b355c75e33d0c925b27ba3f301d100a51b (patch) | |
tree | 740a78446f898623b9fe46745bb53707e568644c /src/System.Private.CoreLib | |
parent | d3b9f9dac784c03e10619ff49c8f22579940192c (diff) | |
download | coreclr-dadee3b355c75e33d0c925b27ba3f301d100a51b.tar.gz coreclr-dadee3b355c75e33d0c925b27ba3f301d100a51b.tar.bz2 coreclr-dadee3b355c75e33d0c925b27ba3f301d100a51b.zip |
Updated InsertItemsRange to simplify the expression and added performance improvements. If the underlying `items` is using List<T> we should use it's InsertRange method since it is optimized, othersie we use InsertItem
Diffstat (limited to 'src/System.Private.CoreLib')
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs index ea7bcb3fa9..1a83b3fd39 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs @@ -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); + } } } |