From 70c9f16f5e656942249651bfafc3357cd4bbf397 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 15 Aug 2023 10:15:48 -0400 Subject: [PATCH] Address PR feedback --- .../src/System/Collections/Frozen/FrozenDictionary.cs | 2 ++ .../src/System/Collections/Frozen/FrozenSet.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs index 02ea95e4a8737..e4fbdcef00b3c 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs @@ -113,6 +113,8 @@ public static FrozenDictionary ToFrozenDictionary CreateFromDictionary(Dictionary source) where TKey : notnull { + Debug.Assert(source.Count > 0, "Empty sources should have been filtered out by caller"); + IEqualityComparer comparer = source.Comparer; // Optimize for value types when the default comparer is being used. In such a case, the implementation diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenSet.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenSet.cs index ed472ff80666a..8c315f214fe03 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenSet.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenSet.cs @@ -59,6 +59,8 @@ public static FrozenSet ToFrozenSet(this IEnumerable source, IEqualityC private static FrozenSet CreateFromSet(HashSet source) { + Debug.Assert(source.Count > 0, "Empty sources should have been filtered out by caller"); + IEqualityComparer comparer = source.Comparer; // Optimize for value types when the default comparer is being used. In such a case, the implementation