diff options
author | Stephen Toub <stoub@microsoft.com> | 2018-10-17 23:52:11 -0400 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2018-10-17 20:52:11 -0700 |
commit | 4b98caf278c8ac42f14ed90489d2566639018b04 (patch) | |
tree | 128f12dfea4ff9cc5abe35c52f2edf772189259a | |
parent | 692925708ac2f600d41c07eeaf729d219264d0d5 (diff) | |
download | coreclr-4b98caf278c8ac42f14ed90489d2566639018b04.tar.gz coreclr-4b98caf278c8ac42f14ed90489d2566639018b04.tar.bz2 coreclr-4b98caf278c8ac42f14ed90489d2566639018b04.zip |
Revert List.InsertRange changes from #8306 (#20471)
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Collections/Generic/List.cs | 41 |
1 files changed, 8 insertions, 33 deletions
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 698abe9cf5..f1bb6512cb 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 @@ namespace System.Collections.Generic { _size = 0; _items = s_emptyArray; - AddEnumerable(collection); + using (IEnumerator<T> en = collection.GetEnumerator()) + { + while (en.MoveNext()) + { + Add(en.Current); + } + } } } @@ -748,9 +754,8 @@ namespace System.Collections.Generic _size += count; } } - else if (index < _size) + else { - // We're inserting a lazy enumerable. Call Insert on each of the constituent items. using (IEnumerator<T> en = collection.GetEnumerator()) { while (en.MoveNext()) @@ -759,11 +764,6 @@ namespace System.Collections.Generic } } } - else - { - // We're adding a lazy enumerable because the index is at the end of this list. - AddEnumerable(collection); - } _version++; } @@ -1089,31 +1089,6 @@ namespace System.Collections.Generic return true; } - private void AddEnumerable(IEnumerable<T> enumerable) - { - Debug.Assert(enumerable != null); - Debug.Assert(!(enumerable is ICollection<T>), "We should have optimized for this beforehand."); - - _version++; // Even if the enumerable has no items, we can update _version. - using (IEnumerator<T> 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<T>, IEnumerator { private readonly List<T> _list; |