Optimise LinqBridge Count

This commit is contained in:
Jon Hanna
2017-01-04 15:17:22 +00:00
parent e08d1f7524
commit dbc7374995
+15 -3
View File
@@ -711,9 +711,21 @@ namespace Newtonsoft.Json.Utilities.LinqBridge
CheckNotNull(source, "source");
var collection = source as ICollection;
return collection != null
? collection.Count
: source.Aggregate(0, (count, item) => checked(count + 1));
if (collection != null)
{
return collection.Count;
}
using (var en = source.GetEnumerator())
{
int count = 0;
while (en.MoveNext())
{
++count;
}
return count;
}
}
/// <summary>