mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-13 03:35:04 +00:00
Removing extremely slow collection extensions
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user