From adb64514f8f4c88f6d12225def5bbf95ebb8c930 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 2 Nov 2017 23:45:09 +0100 Subject: [PATCH] Add some comments to SwitchDetection.UseCSharpSwitch --- ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs index 8473c17bf..8a959d7a5 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs @@ -158,7 +158,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow return false; } defaultSection = analysis.Sections.FirstOrDefault(s => s.Key.Count() > MaxValuesPerSection); - if (defaultSection.Key.IsEmpty) { + if (defaultSection.Value == null) { + // no default section found? + // This should never happen, as we'd need 2^64/MaxValuesPerSection sections to hit this case... return false; } ulong valuePerSectionLimit = MaxValuesPerSection; @@ -173,9 +175,12 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow var defaultSectionKey = defaultSection.Key; if (analysis.Sections.Any(s => !s.Key.SetEquals(defaultSectionKey) && s.Key.Count() > valuePerSectionLimit)) { + // Only the default section is allowed to have tons of keys. + // C# doesn't support "case 1 to 100000000", and we don't want to generate + // gigabytes of case labels. return false; } - return analysis.InnerBlocks.Any(); + return true; } } }