diff --git a/src/System.Private.CoreLib/shared/System/Collections/Generic/List.cs b/src/System.Private.CoreLib/shared/System/Collections/Generic/List.cs index 698abe9cf59d..f1bb6512cbcb 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Generic/List.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Generic/List.cs @@ -82,7 +82,13 @@ public List(IEnumerable collection) { _size = 0; _items = s_emptyArray; - AddEnumerable(collection); + using (IEnumerator en = collection.GetEnumerator()) + { + while (en.MoveNext()) + { + Add(en.Current); + } + } } } @@ -748,9 +754,8 @@ public void InsertRange(int index, IEnumerable collection) _size += count; } } - else if (index < _size) + else { - // We're inserting a lazy enumerable. Call Insert on each of the constituent items. using (IEnumerator en = collection.GetEnumerator()) { while (en.MoveNext()) @@ -759,11 +764,6 @@ public void InsertRange(int index, IEnumerable collection) } } } - else - { - // We're adding a lazy enumerable because the index is at the end of this list. - AddEnumerable(collection); - } _version++; } @@ -1089,31 +1089,6 @@ public bool TrueForAll(Predicate match) return true; } - private void AddEnumerable(IEnumerable enumerable) - { - 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()) - { - - while (en.MoveNext()) - { - // Capture Current before doing anything else. If this throws - // an exception, we want to make a clean break. - T current = en.Current; - - if (_size == _items.Length) - { - EnsureCapacity(_size + 1); - } - - _items[_size++] = current; - } - } - } - public struct Enumerator : IEnumerator, IEnumerator { private readonly List _list;