From 8cc8a9f94de9640a7e9cf126deb5dcfa2339e146 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Apr 2020 17:22:48 +0200 Subject: [PATCH] Minor codegen improvement --- .../DictionarySlim{TKey,TValue}.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Mvvm/Messaging/Microsoft.Collections.Extensions/DictionarySlim{TKey,TValue}.cs b/Microsoft.Toolkit.Mvvm/Messaging/Microsoft.Collections.Extensions/DictionarySlim{TKey,TValue}.cs index 7597d309..a65bf440 100644 --- a/Microsoft.Toolkit.Mvvm/Messaging/Microsoft.Collections.Extensions/DictionarySlim{TKey,TValue}.cs +++ b/Microsoft.Toolkit.Mvvm/Messaging/Microsoft.Collections.Extensions/DictionarySlim{TKey,TValue}.cs @@ -243,7 +243,7 @@ namespace Microsoft.Collections.Extensions if ((uint)newSize > int.MaxValue) { - throw new InvalidOperationException("Max capacity exceeded"); + ThrowInvalidOperationExceptionForMaxCapacityExceeded(); } var entries = new Entry[newSize]; @@ -328,5 +328,14 @@ namespace Microsoft.Collections.Extensions { throw new ArgumentException($"The target key {key} was not present in the dictionary"); } + + /// + /// Throws an when trying to resize over the maximum capacity. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + private static void ThrowInvalidOperationExceptionForMaxCapacityExceeded() + { + throw new InvalidOperationException("Max capacity exceeded"); + } } } \ No newline at end of file