Skip to content

Commit

Permalink
Avoid boxing if property is correct type.
Browse files Browse the repository at this point in the history
For typed bindings, we'll have an `AvaloniaPropertyChangedEventArgs<T>` where `T` is the same as the type of the `AvaloniaPropertyObservable`. For non-typed bindings we'll have `object` as `T` so use the non-typed `AvaloniaProperty`.
  • Loading branch information
grokys committed Jan 20, 2020
1 parent 1ff6e35 commit c2d5f62
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ private void PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
{
if (e.Property == _property)
{
var newValue = e.Sender.GetValue(e.Property);
T newValue;

if (e is AvaloniaPropertyChangedEventArgs<T> typed)
{
newValue = typed.Sender.GetValue(typed.Property);
}
else
{
newValue = (T)e.Sender.GetValue(e.Property);
}

if (!Equals(newValue, _value))
{
Expand Down

0 comments on commit c2d5f62

Please sign in to comment.