Repository navigation
feat: Switch MoveNext to foreach - #23199
Conversation
|
|
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
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
foreachin layout, resource resolution, visual state, and templating code paths. - Removed explicit enumerator disposal patterns that were only present to avoid implicit
try/finallyoverhead 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.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23199/wasm-skia-net9/index.html |
|
|
carldebilly
left a comment
There was a problem hiding this comment.
Definitely not required anymore
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23199/wasm-skia-net9/index.html |
|
The build 211827 found UI Test snapshots differences: Details
|
Removes the manual
GetEnumerator()/while (MoveNext())workarounds that were introduced to avoidtry/catchoverhead 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
foreachloops across 12 files:DependencyObjectStore.cs– 2 instances in inherited property propagationGrid.cs– 3 instances:ValidateDefinitions,MeasureOverride,ArrangeOverrideUIElement.Layout.crossruntime.cs– 2 instances in measure/arrange dirty-path traversal (also removedchildren.Dispose()Wasm workaround comments)FrameworkElement.EffectiveViewport.cs– viewport update loop; preservedtry/finallyflag but removed explicitenumerator.Dispose()ResourceResolver.cs– 2 instances inTryStaticRetrievalFrameworkElementHelper.cs– 2 instances inSetUseMeasurePathDisabled/SetUseArrangePathDisabledVisualStateGroup.cs– uses directforeach+is Setterpattern match to avoid LINQ allocation in the hot pathUIElementCollection.cs,ItemsControl.cs,FrameworkTemplatePool.cs,ILayouterElement.cs– 1 instance eachBefore:
After:
PR Checklist ✅
Screenshots Compare Test Runresults.