Author: jbevain
Date: 2007-11-08 09:18:19 -0500 (Thu, 08 Nov 2007)
New Revision: 89188

Modified:
   trunk/mcs/class/System.Core/System.Linq/ChangeLog
   trunk/mcs/class/System.Core/System.Linq/Enumerable.cs
Log:
2007-11-08  Jb Evain  <[EMAIL PROTECTED]>

        * Enumerable.cs: correctly implement Intersect.



Modified: trunk/mcs/class/System.Core/System.Linq/ChangeLog
===================================================================
--- trunk/mcs/class/System.Core/System.Linq/ChangeLog   2007-11-08 14:17:39 UTC 
(rev 89187)
+++ trunk/mcs/class/System.Core/System.Linq/ChangeLog   2007-11-08 14:18:19 UTC 
(rev 89188)
@@ -1,5 +1,9 @@
 2007-11-08  Jb Evain  <[EMAIL PROTECTED]>
 
+       * Enumerable.cs: correctly implement Intersect.
+
+2007-11-08  Jb Evain  <[EMAIL PROTECTED]>
+
        * Enumerable.cs: code cleanup.
 
 2007-11-06  Jb Evain  <[EMAIL PROTECTED]>

Modified: trunk/mcs/class/System.Core/System.Linq/Enumerable.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq/Enumerable.cs       2007-11-08 
14:17:39 UTC (rev 89187)
+++ trunk/mcs/class/System.Core/System.Linq/Enumerable.cs       2007-11-08 
14:18:19 UTC (rev 89188)
@@ -869,26 +869,24 @@
 
                #region Intersect
 
-
                public static IEnumerable<TSource> Intersect<TSource> (this 
IEnumerable<TSource> first, IEnumerable<TSource> second)
                {
+                       return Intersect (first, second, null);
+               }
+
+               public static IEnumerable<TSource> Intersect<TSource> (this 
IEnumerable<TSource> first, IEnumerable<TSource> second, 
IEqualityComparer<TSource> comparer)
+               {
                        if (first == null || second == null)
                                throw new ArgumentNullException ();
 
-                       List<TSource> items = new List<TSource> (Distinct 
(first));
-                       bool [] marked = new bool [items.Count];
-                       for (int i = 0; i < marked.Length; i++)
-                               marked [i] = false;
+                       if (comparer == null)
+                               comparer = EqualityComparer<TSource>.Default;
 
+                       List<TSource> items = new List<TSource> (Distinct 
(first));
                        foreach (TSource element in second) {
-                               int index = IndexOf (items, element);
-                               if (index != -1)
-                                       marked [index] = true;
+                               if (Contains (items, element, comparer))
+                                       yield return element;
                        }
-                       for (int i = 0; i < marked.Length; i++) {
-                               if (marked [i])
-                                       yield return items [i];
-                       }
                }
 
                #endregion

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to