Removing extremely slow collection extensions

This commit is contained in:
Chris Cameron
2017-11-10 14:32:13 -05:00
parent ab6223a014
commit f546a7d8c4
3 changed files with 0 additions and 85 deletions

View File

@@ -1,34 +0,0 @@
using System.Collections.Generic;
using ICD.Common.Utils.Extensions;
using NUnit.Framework;
namespace ICD.Common.Utils.Tests.Extensions
{
[TestFixture]
public sealed class CollectionExtensionsTest
{
[Test]
public void RemoveAllPredicateTest()
{
List<int> a = new List<int> {1, 2, 2, 3};
List<int> b = new List<int> {2, 3};
((ICollection<int>)a).RemoveAll(i => b.Contains(i));
Assert.AreEqual(1, a.Count);
Assert.AreEqual(1, a[0]);
}
[Test]
public void RemoveAllOtherTest()
{
List<int> a = new List<int> {1, 2, 2, 3};
List<int> b = new List<int> {2, 3};
a.RemoveAll(b);
Assert.AreEqual(1, a.Count);
Assert.AreEqual(1, a[0]);
}
}
}

View File

@@ -1,50 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ICD.Common.Properties;
namespace ICD.Common.Utils.Extensions
{
/// <summary>
/// Extension methods for working with ICollections.
/// </summary>
public static class CollectionExtensions
{
/// <summary>
/// Removes all of the items from the other collection.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <param name="other"></param>
[PublicAPI]
public static void RemoveAll<T>(this ICollection<T> extends, IEnumerable<T> other)
{
if (extends == null)
throw new ArgumentNullException("extends");
if (other == null)
throw new ArgumentNullException("other");
extends.RemoveAll(other.Contains);
}
/// <summary>
/// Removes items matching the predicate.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <param name="predicate"></param>
[PublicAPI]
public static void RemoveAll<T>(this ICollection<T> extends, Func<T, bool> predicate)
{
if (extends == null)
throw new ArgumentNullException("extends");
if (predicate == null)
throw new ArgumentNullException("predicate");
foreach (T item in extends.Where(predicate).ToArray())
extends.Remove(item);
}
}
}

View File

@@ -113,7 +113,6 @@
<Compile Include="IO\IcdDirectory.cs" />
<Compile Include="EnumUtils.cs" />
<Compile Include="Extensions\AssemblyExtensions.cs" />
<Compile Include="Extensions\CollectionExtensions.cs" />
<Compile Include="Extensions\DictionaryExtensions.cs" />
<Compile Include="Extensions\EnumerableExtensions.cs" />
<Compile Include="Extensions\EnumExtensions.cs" />