Skip to content

Commit 6e65a5d

Browse files
committed
Address feedback
1 parent ccbd9e5 commit 6e65a5d

File tree

1 file changed

+9
-19
lines changed
  • src/libraries/System.Linq/src/System/Linq

1 file changed

+9
-19
lines changed

src/libraries/System.Linq/src/System/Linq/Count.cs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,10 @@ public static int Count<TSource>(this IEnumerable<TSource> source, Func<TSource,
6060
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
6161
}
6262

63-
return source.TryGetSpan(out ReadOnlySpan<TSource> span)
64-
? CountSpan(span, predicate)
65-
: CountEnumerable(source, predicate);
66-
67-
[StackTraceHidden]
68-
static int CountSpan(ReadOnlySpan<TSource> source, Func<TSource, bool> predicate)
63+
int count = 0;
64+
if (source.TryGetSpan(out ReadOnlySpan<TSource> span))
6965
{
70-
int count = 0;
71-
foreach (TSource element in source)
66+
foreach (TSource element in span)
7267
{
7368
if (predicate(element))
7469
{
@@ -79,23 +74,18 @@ static int CountSpan(ReadOnlySpan<TSource> source, Func<TSource, bool> predicate
7974
return count;
8075
}
8176

82-
[StackTraceHidden]
83-
static int CountEnumerable(IEnumerable<TSource> source, Func<TSource, bool> predicate)
77+
foreach (TSource element in source)
8478
{
85-
int count = 0;
86-
foreach (TSource element in source)
79+
checked
8780
{
88-
checked
81+
if (predicate(element))
8982
{
90-
if (predicate(element))
91-
{
92-
count++;
93-
}
83+
count++;
9484
}
9585
}
96-
97-
return count;
9886
}
87+
88+
return count;
9989
}
10090

10191
/// <summary>

0 commit comments

Comments
 (0)