-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(perf): Fix lazy creation of ShapeCollection when not needed
- Loading branch information
Showing
1 changed file
with
28 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
#nullable enable | ||
|
||
namespace Windows.UI.Composition | ||
namespace Windows.UI.Composition; | ||
|
||
public partial class ShapeVisual : ContainerVisual | ||
{ | ||
public partial class ShapeVisual : ContainerVisual | ||
private CompositionViewBox? _viewBox; | ||
private CompositionShapeCollection? _shapes; | ||
|
||
public ShapeVisual(Compositor compositor) | ||
: base(compositor) | ||
{ | ||
private CompositionViewBox? _viewBox; | ||
private CompositionShapeCollection? _shapes; | ||
} | ||
|
||
public ShapeVisual(Compositor compositor) | ||
: base(compositor) | ||
{ | ||
// Add this as context for the shape collection so we get | ||
// notified about changes in the shapes object graph. | ||
OnCompositionPropertyChanged(null, Shapes, nameof(Shapes)); | ||
} | ||
public CompositionViewBox? ViewBox | ||
{ | ||
get => _viewBox; | ||
set => SetProperty(ref _viewBox, value); | ||
} | ||
|
||
public CompositionViewBox? ViewBox | ||
// This is lazy as we are using the `ShapeVisual` for UIElement, but lot of them are not creating shapes, reduce memory pressure. | ||
public CompositionShapeCollection Shapes | ||
{ | ||
get | ||
{ | ||
get => _viewBox; | ||
set => SetProperty(ref _viewBox, value); | ||
} | ||
if (_shapes is null) | ||
{ | ||
_shapes = new CompositionShapeCollection(Compositor, this); | ||
|
||
// This ia lazy as we are using the `ShapeVisual` for UIElement, but lot of them are not creating shapes, reduce memory pressure. | ||
public CompositionShapeCollection Shapes => _shapes ??= new CompositionShapeCollection(Compositor, this); | ||
// Add this as context for the shape collection so we get | ||
// notified about changes in the shapes object graph. | ||
OnCompositionPropertyChanged(null, _shapes, nameof(Shapes)); | ||
} | ||
|
||
return _shapes; | ||
} | ||
} | ||
} |