Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJb Evain <jbevain@gmail.com>2008-05-09 01:25:28 +0400
committerJb Evain <jbevain@gmail.com>2008-05-09 01:25:28 +0400
commita7dfd8b42f4cb462c6b64cc876ab4aef080646b1 (patch)
tree936c6c07afb2ccdd024f2870849655a1f90393c4 /mcs/class/System.Core/System.Linq/Enumerable.cs
parent6915192aa97a1c6cd7fd4d75c569c691b5b37f3f (diff)
optimize ToArray a bit
svn path=/trunk/mcs/; revision=102836
Diffstat (limited to 'mcs/class/System.Core/System.Linq/Enumerable.cs')
-rw-r--r--mcs/class/System.Core/System.Linq/Enumerable.cs11
1 files changed, 9 insertions, 2 deletions
diff --git a/mcs/class/System.Core/System.Linq/Enumerable.cs b/mcs/class/System.Core/System.Linq/Enumerable.cs
index 73f511ab13b..fe7614b1e52 100644
--- a/mcs/class/System.Core/System.Linq/Enumerable.cs
+++ b/mcs/class/System.Core/System.Linq/Enumerable.cs
@@ -2209,12 +2209,19 @@ namespace System.Linq
#endregion
#region ToArray
+
public static TSource [] ToArray<TSource> (this IEnumerable<TSource> source)
{
Check.Source (source);
- List<TSource> list = new List<TSource> (source);
- return list.ToArray ();
+ var collection = source as ICollection<TSource>;
+ if (collection != null) {
+ var array = new TSource [collection.Count];
+ collection.CopyTo (array, 0);
+ return array;
+ }
+
+ return new List<TSource> (source).ToArray ();
}
#endregion