Browse Source

Merge pull request #2895 from AvaloniaUI/animations-alloc

Animations subsystem perf fixes.
pull/2993/head
Jumar Macato 7 years ago
committed by GitHub
parent
commit
fa1696e6c8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/Avalonia.Animation/Animatable.cs

17
src/Avalonia.Animation/Animatable.cs

@ -45,16 +45,17 @@ namespace Avalonia.Animation
{ {
get get
{ {
if (_transitions == null) if (_transitions is null)
_transitions = new Transitions(); _transitions = new Transitions();
if (_previousTransitions == null) if (_previousTransitions is null)
_previousTransitions = new Dictionary<AvaloniaProperty, IDisposable>(); _previousTransitions = new Dictionary<AvaloniaProperty, IDisposable>();
return _transitions; return _transitions;
} }
set set
{ {
SetAndRaise(TransitionsProperty, ref _transitions, value); SetAndRaise(TransitionsProperty, ref _transitions, value);
} }
} }
@ -66,18 +67,20 @@ namespace Avalonia.Animation
/// <param name="e">The event args.</param> /// <param name="e">The event args.</param>
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e) protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{ {
if (e.Priority != BindingPriority.Animation && Transitions != null && _previousTransitions != null) if (_transitions is null || _previousTransitions is null || e.Priority == BindingPriority.Animation) return;
{
var match = Transitions.FirstOrDefault(x => x.Property == e.Property);
if (match != null) // PERF-SENSITIVE: Called on every property change. Don't use LINQ here (too many allocations).
foreach (var transition in Transitions)
{
if (transition.Property == e.Property)
{ {
if (_previousTransitions.TryGetValue(e.Property, out var dispose)) if (_previousTransitions.TryGetValue(e.Property, out var dispose))
dispose.Dispose(); dispose.Dispose();
var instance = match.Apply(this, Clock ?? Avalonia.Animation.Clock.GlobalClock, e.OldValue, e.NewValue); var instance = transition.Apply(this, Clock ?? Avalonia.Animation.Clock.GlobalClock, e.OldValue, e.NewValue);
_previousTransitions[e.Property] = instance; _previousTransitions[e.Property] = instance;
return;
} }
} }
} }

Loading…
Cancel
Save