Browse Source

perf: Cache the last matrix instead of iterating the children on each `TransformGroup.Value` property call (#13532)

pull/13688/head
workgroupengineering 2 years ago
committed by GitHub
parent
commit
efc7ef566a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      src/Avalonia.Base/Media/TransformGroup.cs

22
src/Avalonia.Base/Media/TransformGroup.cs

@ -14,16 +14,20 @@ namespace Avalonia.Media
private IDisposable? _childrenNotificationSubscription;
private readonly EventHandler _childTransformChangedHandler;
private Matrix? _lastMatrix;
[System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1012",
Justification = "Collection properties shouldn't be set with SetCurrentValue.")]
public TransformGroup()
{
_childTransformChangedHandler = (_, _) => RaiseChanged();
_childTransformChangedHandler = (_, _) =>
{
_lastMatrix = null;
RaiseChanged();
};
Children = new Transforms();
}
/// <summary>
/// Gets or sets the children.
/// </summary>
@ -44,14 +48,16 @@ namespace Avalonia.Media
{
get
{
Matrix result = Matrix.Identity;
foreach (var t in Children)
if (_lastMatrix is null)
{
result *= t.Value;
var matrix = Matrix.Identity;
foreach (var t in Children)
{
matrix *= t.Value;
}
_lastMatrix = matrix;
}
return result;
return _lastMatrix.Value;
}
}

Loading…
Cancel
Save