diff options
author | Stephen Toub <stoub@microsoft.com> | 2016-01-21 07:52:34 -0500 |
---|---|---|
committer | Stephen Toub <stoub@microsoft.com> | 2016-01-21 07:52:34 -0500 |
commit | 9a43c440f840a0bf89ba2c2efb9d6fd5baaf8dea (patch) | |
tree | 8d20ac8710e64af42fb988877e56978261fdaf0e /src/mscorlib | |
parent | d67baec3b7e93dd5722d0428c96a2800308ec308 (diff) | |
parent | 5bcecb93e9843dc5ea6b172bc20119571f202c6e (diff) | |
download | coreclr-9a43c440f840a0bf89ba2c2efb9d6fd5baaf8dea.tar.gz coreclr-9a43c440f840a0bf89ba2c2efb9d6fd5baaf8dea.tar.bz2 coreclr-9a43c440f840a0bf89ba2c2efb9d6fd5baaf8dea.zip |
Merge pull request #2758 from stephentoub/list_toarray
Use _emptyArray in List<T>.ToArray
Diffstat (limited to 'src/mscorlib')
-rw-r--r-- | src/mscorlib/src/System/Collections/Generic/List.cs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/mscorlib/src/System/Collections/Generic/List.cs b/src/mscorlib/src/System/Collections/Generic/List.cs index 5a89c24328..869a15f0ce 100644 --- a/src/mscorlib/src/System/Collections/Generic/List.cs +++ b/src/mscorlib/src/System/Collections/Generic/List.cs @@ -1001,12 +1001,19 @@ namespace System.Collections.Generic { } } - // ToArray returns a new Object array containing the contents of the List. + // ToArray returns an array containing the contents of the List. // This requires copying the List, which is an O(n) operation. public T[] ToArray() { Contract.Ensures(Contract.Result<T[]>() != null); Contract.Ensures(Contract.Result<T[]>().Length == Count); +#if FEATURE_CORECLR + if (_size == 0) + { + return _emptyArray; + } +#endif + T[] array = new T[_size]; Array.Copy(_items, 0, array, 0, _size); return array; |