Browse Source

update docs and remove value tuple that could cause allocation.

pull/18223/head
Dan Walmsley 12 months ago
parent
commit
9c1d9d595d
  1. 15
      src/Avalonia.Base/AvaloniaPropertyChangedEventArgs.cs
  2. 28
      src/Avalonia.Base/PropertyStore/ValueStore.cs

15
src/Avalonia.Base/AvaloniaPropertyChangedEventArgs.cs

@ -27,11 +27,6 @@ namespace Avalonia
IsEffectiveValueChange = isEffectiveValueChange;
}
internal void SetSender(AvaloniaObject sender)
{
Sender = sender;
}
/// <summary>
/// Gets the <see cref="AvaloniaObject"/> that the property changed on.
/// </summary>
@ -65,6 +60,16 @@ namespace Avalonia
public BindingPriority Priority { get; private set; }
internal bool IsEffectiveValueChange { get; private set; }
/// <summary>
/// Sets the Sender property.
/// This is purely for reuse in some code paths where multiple allocations may occur.
/// </summary>
/// <param name="sender">The sender object.</param>
internal void SetSender(AvaloniaObject sender)
{
Sender = sender;
}
protected abstract AvaloniaProperty GetProperty();
protected abstract object? GetOldValue();

28
src/Avalonia.Base/PropertyStore/ValueStore.cs

@ -592,11 +592,12 @@ namespace Avalonia.PropertyStore
var count = children.Count;
var args = GetPropertyChangedEventArgs(Owner, property, oldValue, value.Value);
var apArgs = new AvaloniaPropertyChangedEventArgs<T>(Owner, property, oldValue, value.Value, BindingPriority.Inherited, true);
var incpArgs = new PropertyChangedEventArgs(property.Name);
for (var i = 0; i < count; ++i)
{
children[i].GetValueStore().OnAncestorInheritedValueChanged(args.apArgs, args.incpArgs);
children[i].GetValueStore().OnAncestorInheritedValueChanged(apArgs, incpArgs);
}
}
@ -616,12 +617,13 @@ namespace Avalonia.PropertyStore
if (children is not null)
{
var count = children.Count;
var args = GetPropertyChangedEventArgs(Owner, property, oldValue, newValue);
var apArgs = new AvaloniaPropertyChangedEventArgs<T>(Owner, property, oldValue, newValue, BindingPriority.Inherited, true);
var incpArgs = new PropertyChangedEventArgs(property.Name);
for (var i = 0; i < count; ++i)
{
children[i].GetValueStore().OnAncestorInheritedValueChanged(args.apArgs, args.incpArgs);
children[i].GetValueStore().OnAncestorInheritedValueChanged(apArgs, incpArgs);
}
}
}
@ -644,25 +646,13 @@ namespace Avalonia.PropertyStore
}
}
}
private (AvaloniaPropertyChangedEventArgs<T> apArgs, PropertyChangedEventArgs? incpArgs)
GetPropertyChangedEventArgs<T>(AvaloniaObject sender,
StyledProperty<T> property,
T oldValue,
T newValue)
{
Debug.Assert(property.Inherits);
return new (new AvaloniaPropertyChangedEventArgs<T>(sender, property, oldValue, newValue, BindingPriority.Inherited, true), new PropertyChangedEventArgs(property.Name));
}
/// <summary>
/// Called when an inherited property changes on the value store of the inheritance ancestor.
/// </summary>
/// <typeparam name="T">The property type.</typeparam>
/// <param name="property">The property.</param>
/// <param name="oldValue">The old value of the property.</param>
/// <param name="newValue">The new value of the property.</param>
/// <param name="apArgs">Avalonia Property EventArgs to reuse.</param>
/// <param name="args">PropertyChangedEventArgs to reuse</param>
public void OnAncestorInheritedValueChanged<T>(AvaloniaPropertyChangedEventArgs<T> apArgs, PropertyChangedEventArgs? args)
{

Loading…
Cancel
Save