diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs b/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs index d1a400bab20..f30a25032dc 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs @@ -245,39 +245,20 @@ static void EnsureIdenticalCollections (TaskLoggingHelper logger, NativeCodeGenS { logger.LogDebugMessage ($"Ensuring Java type collection in architecture '{state.TargetArch}' matches the one in architecture '{templateState.TargetArch}'"); - List templateTypes = templateState.AllJavaTypes; - List types = state.AllJavaTypes; + var templateSet = new SortedSet (templateState.AllJavaTypes.Select (t => t.FullName), StringComparer.Ordinal); + var typesSet = new SortedSet (state.AllJavaTypes.Select (t => t.FullName), StringComparer.Ordinal); - if (types.Count != templateTypes.Count) { - throw new InvalidOperationException ($"Internal error: architecture '{state.TargetArch}' has a different number of types ({types.Count}) than the template architecture '{templateState.TargetArch}' ({templateTypes.Count})"); + if (typesSet.Count != templateSet.Count) { + throw new InvalidOperationException ($"Internal error: architecture '{state.TargetArch}' has a different number of types ({typesSet.Count}) than the template architecture '{templateState.TargetArch}' ({templateSet.Count})"); } - var matchedTemplateTypes = new HashSet (); - var mismatchedTypes = new List (); - - foreach (TypeDefinition type in types) { - TypeDefinition? matchedType = null; - - foreach (TypeDefinition templateType in templateTypes) { - if (matchedTemplateTypes.Contains (templateType) || !CheckWhetherTypesMatch (templateType, type)) { - continue; - } - - matchedTemplateTypes.Add (templateType); - matchedType = templateType; - break; - } + if (!typesSet.SetEquals (templateSet)) { + logger.LogError ($"Architecture '{state.TargetArch}' has Java types which have no counterparts in template architecture '{templateState.TargetArch}':"); - if (matchedType == null) { - mismatchedTypes.Add (type); - } - } + typesSet.ExceptWith (templateSet); - if (mismatchedTypes.Count > 0) { - logger.LogError ($"Architecture '{state.TargetArch}' has Java types which have no counterparts in template architecture '{templateState.TargetArch}':"); - foreach (TypeDefinition td in mismatchedTypes) { - logger.LogError ($" {td.FullName}"); - } + foreach (var type in typesSet) + logger.LogError ($" {type}"); } }