Skip to content

Commit f5c7a5e

Browse files
committed
Use .NET 6 API Enumerable.TryGetNonEnumeratedCount
1 parent 88550c9 commit f5c7a5e

File tree

2 files changed

+2
-29
lines changed

2 files changed

+2
-29
lines changed

src/TfvcMigrator/AsyncParallelQueue.AtomicOperations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public AtomicOperations(IEnumerable<Task<T>> source)
5353
this.source = source.GetEnumerator();
5454

5555
completedTasks = new ArrayBuilder<Task<T>>(
56-
initialCapacity: CommonUtils.TryGetCollectionCount(source, out var count) ? count : 0);
56+
initialCapacity: source.TryGetNonEnumeratedCount(out var count) ? count : 0);
5757
}
5858

5959
public NextOperation TryStartNext()

src/TfvcMigrator/CommonUtils.cs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
1-
using System.Collections;
2-
3-
namespace TfvcMigrator;
1+
namespace TfvcMigrator;
42

53
internal static class CommonUtils
64
{
7-
public static bool TryGetCollectionCount<T>(IEnumerable<T> enumerable, out int count)
8-
{
9-
switch (enumerable)
10-
{
11-
case null:
12-
throw new ArgumentNullException(nameof(enumerable));
13-
14-
case IReadOnlyCollection<T> collection:
15-
count = collection.Count;
16-
return true;
17-
18-
case ICollection<T> collection:
19-
count = collection.Count;
20-
return true;
21-
22-
case ICollection collection:
23-
count = collection.Count;
24-
return true;
25-
26-
default:
27-
count = default;
28-
return false;
29-
}
30-
}
31-
325
public static void EnsureCapacity<T>([NotNull] ref T[]? array, int minCapacity)
336
{
347
if (minCapacity < 0)

0 commit comments

Comments
 (0)