فهرست منبع

2009-08-07 Marek Safar <[email protected]>

	* Enumerable.cs (Skip): Optimized and fixed int.MaxValue overflow.


svn path=/trunk/mcs/; revision=139558
Marek Safar 16 سال پیش
والد
کامیت
ed47ca25ea
2فایلهای تغییر یافته به همراه14 افزوده شده و 5 حذف شده
  1. 4 0
      mcs/class/System.Core/System.Linq/ChangeLog
  2. 10 5
      mcs/class/System.Core/System.Linq/Enumerable.cs

+ 4 - 0
mcs/class/System.Core/System.Linq/ChangeLog

@@ -1,3 +1,7 @@
+2009-08-07  Marek Safar  <[email protected]>
+
+	* Enumerable.cs (Skip): Optimized and fixed int.MaxValue overflow.
+
 2009-07-20  Jb Evain  <[email protected]>
 
 	* Lookup.cs: avoid a double dictionary lookup on the indexer.

+ 10 - 5
mcs/class/System.Core/System.Linq/Enumerable.cs

@@ -1726,12 +1726,17 @@ namespace System.Linq
 
 		static IEnumerable<TSource> CreateSkipIterator<TSource> (IEnumerable<TSource> source, int count)
 		{
-			int i = 0;
-			foreach (var element in source) {
-				if (i++ < count)
-					continue;
+			var enumerator = source.GetEnumerator ();
+			try {
+				while (count-- > 0)
+					if (!enumerator.MoveNext ())
+						yield break;
 
-				yield return element;
+				while (enumerator.MoveNext ())
+					yield return enumerator.Current;
+
+			} finally {
+				enumerator.Dispose ();
 			}
 		}