Skip to content

Commit b184c61

Browse files
jeromelabanMartinZikmund
authored andcommitted
perf: Additional changes to mitigate PG-AOT dotnet/runtime issue #56309
See unoplatform#7005 for additional details
1 parent c3a32ca commit b184c61

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Uno.UI/UI/Xaml/ResourceResolver.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,14 @@ internal static bool ApplyVisualStateSetter(SpecializedResourceDictionary.Resour
210210
/// </summary>
211211
private static bool TryStaticRetrieval(in SpecializedResourceDictionary.ResourceKey resourceKey, object context, out object value)
212212
{
213-
foreach (var source in CurrentScope.Sources)
213+
// This block is a manual enumeration to avoid the foreach pattern
214+
// See https://github.com/dotnet/runtime/issues/56309 for details
215+
var sourcesEnumerator = CurrentScope.Sources.GetEnumerator();
216+
217+
while(sourcesEnumerator.MoveNext())
214218
{
219+
var source = sourcesEnumerator.Current;
220+
215221
var dictionary = (source.Target as FrameworkElement)?.Resources
216222
?? source.Target as ResourceDictionary;
217223
if (dictionary != null && dictionary.TryGetValue(resourceKey, out value, shouldCheckSystem: false))

src/Uno.UI/UI/Xaml/Style/Style.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ internal void ApplyTo(DependencyObject o, DependencyPropertyValuePrecedences pre
6767
#endif
6868
{
6969
ResourceResolver.PushNewScope(_xamlScope);
70-
foreach (var pair in flattenedSetters)
70+
71+
// This block is a manual enumeration to avoid the foreach pattern
72+
// See https://github.com/dotnet/runtime/issues/56309 for details
73+
var settersEnumerator = flattenedSetters.GetEnumerator();
74+
while (settersEnumerator.MoveNext())
7175
{
72-
pair.Value(o);
76+
settersEnumerator.Current.Value(o);
7377
}
7478

7579
// Check tree for resource binding values, since some Setters may have set ThemeResource-backed values

0 commit comments

Comments
 (0)