Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary allocations on DependencyObjectExtensions.RegisterDisposableNestedPropertyChangedCallback (backport #705) #711

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public override void SetSuperviewNeedsLayout()
// Even though we set the Navigation as the parent of the TitleView,
// it will change to the native control when the view is added (once MovedToSuperview is called).
// This native control is the visual parent but is not a DependencyObject and will not propagate the DataContext.
// In order to ensure the DataContext is propagated properly, we need to notify the renderer that this change has occured
// In order to ensure the DataContext is propagated properly, we need to notify the renderer that this change has occurred
// so we can restore the NavigationBar parent that can propagate the DataContext
public override void MovedToSuperview()
{
Expand Down
7 changes: 3 additions & 4 deletions src/Uno.Toolkit.UI/Extensions/DependencyObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Uno.Disposables;
Expand Down Expand Up @@ -53,12 +53,11 @@ internal static IDisposable RegisterDisposableNestedPropertyChangedCallback(this
.Select(group =>
{
var property = group.Key;
var subProperties = group.ToArray();

var childDisposable = new SerialDisposable();

if (instance.TryGetValue(property, out var dpValue))
{
var childDisposable = new SerialDisposable();
var subProperties = group.ToArray();
childDisposable.Disposable = dpValue?.RegisterDisposableNestedPropertyChangedCallback(callback, subProperties);

var disposable = instance.RegisterDisposablePropertyChangedCallback(property, (s, e) =>
Expand Down