Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,15 @@ public static FrozenDictionary<TKey, TElement> ToFrozenDictionary<TSource, TKey,
newDictionary = source as Dictionary<TKey, TValue>;
if (newDictionary is null || (newDictionary.Count != 0 && !newDictionary.Comparer.Equals(comparer)))
{
newDictionary = new Dictionary<TKey, TValue>(comparer);
int capacity = source switch
{
IDictionary<TKey, TValue> dictionary => dictionary.Count,
IReadOnlyDictionary<TKey, TValue> readOnlyDictionary => readOnlyDictionary.Count,
Comment thread
AndrewP-GH marked this conversation as resolved.
Outdated
ICollection<KeyValuePair<TKey, TValue>> collection => collection.Count,
IReadOnlyCollection<KeyValuePair<TKey, TValue>> readOnlyCollection => readOnlyCollection.Count,
_ => 0,
};
newDictionary = new Dictionary<TKey, TValue>(capacity, comparer);
Comment thread
AndrewP-GH marked this conversation as resolved.
Outdated
foreach (KeyValuePair<TKey, TValue> pair in source)
{
// Dictionary's constructor uses Add, which will throw on duplicates.
Expand Down
Loading