Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc PriorityQueue fixes #48539

Merged
merged 8 commits into from
Mar 5, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ namespace System.Collections.Generic
/// </summary>
internal static partial class EnumerableHelpers
{
/// <summary>Attempt to determine the count of the source enumerable without forcing an enumeration.</summary>
/// <param name="source">The source enumerable.</param>
/// <param name="count">The count determined by the type test.</param>
/// <returns>
/// True if the source enumerable could be determined without enumerating, false otherwise.
/// </returns>
internal static bool TryGetCount<T>(IEnumerable<T> source, out int count)
{
if (source is ICollection<T> ict)
{
count = ict.Count;
return true;
}

count = 0;
return false;
}

/// <summary>Converts an enumerable to an array using the same logic as List{T}.</summary>
/// <param name="source">The enumerable to convert.</param>
/// <param name="length">The number of items stored in the resulting array, 0-indexed.</param>
Expand Down
Loading