فهرست منبع

optimize ToArray a bit

svn path=/trunk/mcs/; revision=102836
Jb Evain 17 سال پیش
والد
کامیت
a7dfd8b42f
1فایلهای تغییر یافته به همراه9 افزوده شده و 2 حذف شده
  1. 9 2
      mcs/class/System.Core/System.Linq/Enumerable.cs

+ 9 - 2
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