diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/Scene.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/Scene.cs index b2e827fa26..b4bf4c799a 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/Scene.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/Scene.cs @@ -12,7 +12,7 @@ namespace Avalonia.Rendering.SceneGraph /// public class Scene : IDisposable { - private readonly Dictionary _index; + private Dictionary _index; /// /// Initializes a new instance of the class. @@ -83,7 +83,7 @@ namespace Avalonia.Rendering.SceneGraph /// The cloned scene. public Scene CloneScene() { - var index = new Dictionary(_index.Count); + var index = new Dictionary(); var root = Clone((VisualNode)Root, null, index); var result = new Scene(root, index, Layers.Clone(), Generation + 1) @@ -162,18 +162,9 @@ namespace Avalonia.Rendering.SceneGraph index.Add(result.Visual, result); - int childCount = source.Children.Count; - - if (childCount > 0) + foreach (var child in source.Children) { - Span children = result.AddChildrenSpan(childCount); - - for (var i = 0; i < childCount; i++) - { - var child = source.Children[i]; - - children[i] = Clone((VisualNode)child, result, index); - } + result.AddChild(Clone((VisualNode)child, result, index)); } return result; diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/SceneLayers.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/SceneLayers.cs index 25f7383a1a..5960b4f560 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/SceneLayers.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/SceneLayers.cs @@ -11,28 +11,16 @@ namespace Avalonia.Rendering.SceneGraph public class SceneLayers : IEnumerable { private readonly IVisual _root; - private readonly List _inner; - private readonly Dictionary _index; + private readonly List _inner = new List(); + private readonly Dictionary _index = new Dictionary(); /// /// Initializes a new instance of the class. /// /// The scene's root visual. - public SceneLayers(IVisual root) : this(root, 0) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The scene's root visual. - /// Initial layer capacity. - public SceneLayers(IVisual root, int capacity) + public SceneLayers(IVisual root) { _root = root; - - _inner = new List(capacity); - _index = new Dictionary(capacity); } /// @@ -96,7 +84,7 @@ namespace Avalonia.Rendering.SceneGraph /// The cloned layers. public SceneLayers Clone() { - var result = new SceneLayers(_root, Count); + var result = new SceneLayers(_root); foreach (var src in _inner) { diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/VisualNode.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/VisualNode.cs index 8cd1a47795..82444a0c29 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/VisualNode.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/VisualNode.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Reactive.Disposables; -using Avalonia.Collections.Pooled; using Avalonia.Media; using Avalonia.Platform; using Avalonia.Utilities; @@ -20,8 +19,8 @@ namespace Avalonia.Rendering.SceneGraph private Rect? _bounds; private double _opacity; - private PooledList _children; - private PooledList> _drawOperations; + private List _children; + private List> _drawOperations; private IRef _drawOperationsRefCounter; private bool _drawOperationsCloned; private Matrix transformRestore; @@ -350,18 +349,6 @@ namespace Avalonia.Rendering.SceneGraph context.Transform = transformRestore; } - /// - /// Inserts default constructed children into collection and returns a span for the newly created range. - /// - /// Count of children that will be added. - /// - internal Span AddChildrenSpan(int count) - { - EnsureChildrenCreated(count); - - return _children.AddSpan(count); - } - private Rect CalculateBounds() { var result = new Rect(); @@ -375,11 +362,11 @@ namespace Avalonia.Rendering.SceneGraph return result; } - private void EnsureChildrenCreated(int capacity = 0) + private void EnsureChildrenCreated() { if (_children == null) { - _children = new PooledList(capacity); + _children = new List(); } } @@ -390,21 +377,13 @@ namespace Avalonia.Rendering.SceneGraph { if (_drawOperations == null) { - _drawOperations = new PooledList>(); + _drawOperations = new List>(); _drawOperationsRefCounter = RefCountable.Create(CreateDisposeDrawOperations(_drawOperations)); _drawOperationsCloned = false; } else if (_drawOperationsCloned) { - var oldDrawOperations = _drawOperations; - - _drawOperations = new PooledList>(oldDrawOperations.Count); - - foreach (var drawOperation in oldDrawOperations) - { - _drawOperations.Add(drawOperation.Clone()); - } - + _drawOperations = new List>(_drawOperations.Select(op => op.Clone())); _drawOperationsRefCounter.Dispose(); _drawOperationsRefCounter = RefCountable.Create(CreateDisposeDrawOperations(_drawOperations)); _drawOperationsCloned = false; @@ -418,16 +397,14 @@ namespace Avalonia.Rendering.SceneGraph /// /// Draw operations that need to be disposed. /// Disposable for given draw operations. - private static IDisposable CreateDisposeDrawOperations(PooledList> drawOperations) + private static IDisposable CreateDisposeDrawOperations(List> drawOperations) { - return Disposable.Create(drawOperations, operations => + return Disposable.Create(() => { - foreach (var operation in operations) + foreach (var operation in drawOperations) { operation.Dispose(); } - - operations.Dispose(); }); } @@ -437,8 +414,6 @@ namespace Avalonia.Rendering.SceneGraph { _drawOperationsRefCounter?.Dispose(); - _children?.Dispose(); - Disposed = true; } }