Skip to content

feat: Switch MoveNext to foreach - #23199

Merged
MartinZikmund merged 4 commits into
masterfrom
copilot/switch-movenext-to-foreach
May 10, 2026
Merged

MartinZikmund merged 4 commits into
masterfrom
copilot/switch-movenext-to-foreach

Conversation

Copilot AI commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Removes the manual GetEnumerator()/while (MoveNext()) workarounds that were introduced to avoid try/catch overhead on WebAssembly. The underlying runtime issue (dotnet/runtime#56309) was fixed in .NET 7.0, making these patterns unnecessary.

PR Type:

🔄 Refactoring (no functional changes, no api changes)

What changed? 🚀

Replaced all manual enumerator patterns with standard foreach loops across 12 files:

  • DependencyObjectStore.cs – 2 instances in inherited property propagation
  • Grid.cs – 3 instances: ValidateDefinitions, MeasureOverride, ArrangeOverride
  • UIElement.Layout.crossruntime.cs – 2 instances in measure/arrange dirty-path traversal (also removed children.Dispose() Wasm workaround comments)
  • FrameworkElement.EffectiveViewport.cs – viewport update loop; preserved try/finally flag but removed explicit enumerator.Dispose()
  • ResourceResolver.cs – 2 instances in TryStaticRetrieval
  • FrameworkElementHelper.cs – 2 instances in SetUseMeasurePathDisabled / SetUseArrangePathDisabled
  • VisualStateGroup.cs – uses direct foreach + is Setter pattern match to avoid LINQ allocation in the hot path
  • UIElementCollection.cs, ItemsControl.cs, FrameworkTemplatePool.cs, ILayouterElement.cs – 1 instance each

Before:

// This block is a manual enumeration to avoid the foreach pattern
// See https://github.com/dotnet/runtime/issues/56309 for details
var enumerator = _updatedProperties.GetEnumerator();
while (enumerator.MoveNext())
{
    var dp = enumerator.Current;
    SetValue(dp, DependencyProperty.UnsetValue, ...);
}

After:

foreach (var dp in _updatedProperties)
{
    SetValue(dp, DependencyProperty.UnsetValue, ...);
}

PR Checklist ✅

Copilot AI requested review from Copilot and removed request for Copilot May 5, 2026 11:06
Copilot AI linked an issue May 5, 2026 that may be closed by this pull request
Copilot AI requested review from Copilot and removed request for Copilot May 5, 2026 11:29
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI requested review from Copilot and removed request for Copilot May 5, 2026 11:33
Copilot AI changed the title [WIP] Refactor MoveNext to foreach pattern feat: Switch MoveNext to foreach May 5, 2026
Copilot AI requested a review from MartinZikmund May 5, 2026 11:34
@MartinZikmund
MartinZikmund requested a review from jeromelaban May 5, 2026 12:10
@MartinZikmund
MartinZikmund marked this pull request as ready for review May 5, 2026 12:10
Copilot AI review requested due to automatic review settings May 5, 2026 12:10
@MartinZikmund

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes enumeration patterns across core Uno.UI XAML/layout code by replacing manual GetEnumerator()/MoveNext() loops (previously used as a WebAssembly workaround) with standard foreach loops, now that the underlying runtime issue is fixed in .NET 7+.

Changes:

  • Replaced manual enumerator loops with foreach in layout, resource resolution, visual state, and templating code paths.
  • Removed explicit enumerator disposal patterns that were only present to avoid implicit try/finally overhead on Wasm.
  • Minor loop-body cleanups while preserving existing behavior (e.g., setter filtering, dirty-path traversal).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Uno.UI/UI/Xaml/DependencyObjectStore.cs Simplifies inherited property cleanup/propagation loops to foreach.
src/Uno.UI/UI/Xaml/Controls/Grid/Grid.cs Switches several children/definitions enumerations to foreach in measure/arrange-related paths.
src/Uno.UI/UI/Xaml/UIElement.Layout.crossruntime.cs Uses foreach for dirty-path traversal of children in measure/arrange loops and removes manual disposal workaround.
src/Uno.UI/UI/Xaml/FrameworkElement.EffectiveViewport.cs Updates viewport propagation child iteration to foreach while preserving the flag-reset try/finally.
src/Uno.UI/UI/Xaml/ResourceResolver.cs Converts resource-scope source enumeration in TryStaticRetrieval overloads to foreach.
src/Uno.UI/UI/Xaml/FrameworkElementHelper.cs Converts eager descendant traversal to foreach in measure/arrange path disabling helpers.
src/Uno.UI/UI/Xaml/VisualStateGroup.cs Converts target setter application loop to foreach (now using OfType<Setter>()).
src/Uno.UI/UI/Xaml/UIElementCollection.cs Converts Clear() post-clear iteration to foreach.
src/Uno.UI/UI/Xaml/Controls/ItemsControl/ItemsControl.cs Converts removed-container cleanup loop to foreach.
src/Uno.UI/UI/Xaml/FrameworkTemplatePool.cs Converts ViewGroup child traversal during template reuse propagation to foreach.
src/Uno.UI/UI/Xaml/ILayouterElement.cs Converts child dirty-path traversal loop to foreach in DoMeasure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Uno.UI/UI/Xaml/VisualStateGroup.cs Resolved
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 210860 has failed on Uno.UI - CI.

@carldebilly carldebilly left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not required anymore

@MartinZikmund
MartinZikmund enabled auto-merge May 10, 2026 15:28
@MartinZikmund

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 211827 found UI Test snapshots differences: skia-linux-screenshots: 58, skia-windows-screenshots: 1174, wasm: 9

Details
  • skia-linux-screenshots: 58 changed over 2346

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Focus_FocusVisual_Properties.png-dark
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • Image_Stretch_None.png-dark
    • Image_Stretch_None.png
    • EllipsemaskingEllipseGrid.png-dark
    • EllipsemaskingEllipseGrid.png
    • Gamepad_CurrentReading.png-dark
  • skia-windows-screenshots: 1174 changed over 2346

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ApplicationViewSpanningRectsPage.png-dark
    • AutoBorderStretchwithtopmargin.png
    • AutoSuggestBox_Description.png
    • Battery.png-dark
    • BitmapImage_vs_SvgImageSource.png
    • BorderBottomwithmargins.png-dark
    • Border_BorderThickness.png
    • Border_Clipped_Change_Property.png-dark
    • Border_Corner_Overlap.png-dark
    • Border_Corner_Overlap.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • Circle.png-dark
    • Circle.png
    • ComboBox_CornerRadius.png-dark
    • ComboBox_CornerRadius.png
    • ContentControl_NoTemplateNoContent.png-dark
    • ContentControl_NoTemplateNoContent.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
  • wasm: 9 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • initial_state
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • Uno.UI.Samples.UITests.ImageTestsControl.Image_Stretch_None
    • UITests.Windows_UI_Xaml.Performance.Performance_1000ButtonsContinuousRendering

@MartinZikmund
MartinZikmund merged commit ecbab80 into master May 10, 2026
46 checks passed
@MartinZikmund
MartinZikmund deleted the copilot/switch-movenext-to-foreach branch May 10, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch MoveNext to foreach

7 participants