Skip to content

Commit 5ad904f

Browse files
[X] avoid enumerating 3 times (#31622)
- fixes #31172
1 parent a373335 commit 5ad904f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Controls/src/Xaml/XamlParser.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ public static Type GetElementType(XmlType xmlType, IXmlLineInfo xmlInfo, Assembl
416416
if (s_xmlnsDefinitions == null)
417417
GatherXmlnsDefinitionAndXmlnsPrefixAttributes(currentAssembly);
418418

419-
IEnumerable<Type> types = xmlType.GetTypeReferences(
419+
var types = xmlType.GetTypeReferences(
420420
s_xmlnsDefinitions,
421421
currentAssembly?.FullName,
422422
(typeInfo) =>
@@ -426,12 +426,13 @@ public static Type GetElementType(XmlType xmlType, IXmlLineInfo xmlInfo, Assembl
426426
return t;
427427
return null;
428428
},
429-
expandToExtension);
429+
expandToExtension).Distinct().ToList();
430430

431431
var typeArguments = xmlType.TypeArguments;
432432
exception = null;
433433

434-
if (!types.Any())
434+
435+
if (types.Count == 0)
435436
{
436437
// This covers the scenario where the AppDomain's loaded
437438
// assemblies might have changed since this method was first
@@ -445,13 +446,13 @@ public static Type GetElementType(XmlType xmlType, IXmlLineInfo xmlInfo, Assembl
445446
}
446447
}
447448

448-
if (types.Distinct().Skip(1).Any())
449+
if (types.Count > 1)
449450
{
450451
exception = new XamlParseException($"Ambiguous type '{xmlType.Name}' in xmlns '{xmlType.NamespaceUri}'", xmlInfo);
451452
return null;
452453
}
453454

454-
var type = types.Distinct().FirstOrDefault();
455+
var type = types.Count == 1 ? types[0] : null;
455456

456457
if (type != null && typeArguments != null)
457458
{

0 commit comments

Comments
 (0)