Skip to content

Commit

Permalink
perf(do): Reduce CallbackManager allocations when no callbacks are re…
Browse files Browse the repository at this point in the history
…gistered
  • Loading branch information
jeromelaban committed Feb 23, 2023
1 parent 82fc8e7 commit 9aa78b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Uno.UI/UI/Xaml/DependencyObjectStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,13 @@ internal IDisposable RegisterPropertyChangedCallback(DependencyProperty property

if (ReferenceEquals(callback.Target, ActualInstance))
{
return propertyDetails.CallbackManager.RegisterCallback(callback);
return propertyDetails.RegisterCallback(callback);
}
else
{
CreateWeakDelegate(callback, out var weakCallback, out var weakDelegateRelease);

var cookie = propertyDetails.CallbackManager.RegisterCallback(weakCallback);
var cookie = propertyDetails.RegisterCallback(weakCallback);

return new RegisterPropertyChangedCallbackForPropertyConditionalDisposable(
callback,
Expand Down Expand Up @@ -1905,7 +1905,7 @@ private void InvokeCallbacks(
}

// Raise the changes for the callbacks register through RegisterPropertyChangedCallback.
propertyDetails.CallbackManager.RaisePropertyChanged(actualInstanceAlias, eventArgs);
propertyDetails.RaisePropertyChanged(actualInstanceAlias, eventArgs);

// Raise the property change for generic handlers
for (var callbackIndex = 0; callbackIndex < _genericCallbacks.Data.Length; callbackIndex++)
Expand Down
8 changes: 6 additions & 2 deletions src/Uno.UI/UI/Xaml/DependencyPropertyDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public void Dispose()
}
}

public DependencyPropertyCallbackManager CallbackManager => _callbackManager ??= new DependencyPropertyCallbackManager();

public DependencyProperty Property { get; }

public PropertyMetadata Metadata => _metadata ??= Property.GetMetadata(_dependencyObjectType);
Expand Down Expand Up @@ -372,6 +370,12 @@ public override string ToString()
return $"DependencyPropertyDetails({Property.Name})";
}

internal IDisposable RegisterCallback(PropertyChangedCallback callback)
=> (_callbackManager ??= new DependencyPropertyCallbackManager()).RegisterCallback(callback);

internal void RaisePropertyChanged(DependencyObject actualInstanceAlias, DependencyPropertyChangedEventArgs eventArgs)
=> _callbackManager?.RaisePropertyChanged(actualInstanceAlias, eventArgs);

[Flags]
enum Flags
{
Expand Down

0 comments on commit 9aa78b5

Please sign in to comment.