committed by
GitHub
58 changed files with 1078 additions and 180 deletions
@ -0,0 +1,15 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
|
|||
namespace Avalonia.Platform |
|||
{ |
|||
public interface IMacOSTopLevelPlatformHandle |
|||
{ |
|||
IntPtr NSView { get; } |
|||
IntPtr GetNSViewRetained(); |
|||
IntPtr NSWindow { get; } |
|||
IntPtr GetNSWindowRetained(); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
namespace Avalonia |
|||
{ |
|||
/// <summary>
|
|||
/// Defines an element with a data context that can be used for binding.
|
|||
/// </summary>
|
|||
public interface IDataContextProvider : IAvaloniaObject |
|||
{ |
|||
/// <summary>
|
|||
/// Gets or sets the element's data context.
|
|||
/// </summary>
|
|||
object DataContext { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
using Avalonia.Data; |
|||
using BenchmarkDotNet.Attributes; |
|||
|
|||
namespace Avalonia.Benchmarks.Data |
|||
{ |
|||
[MemoryDiagnoser, InProcess] |
|||
public class BindingsBenchmark |
|||
{ |
|||
[Benchmark] |
|||
public void TwoWayBinding_Via_Binding() |
|||
{ |
|||
var instance = new TestClass(); |
|||
|
|||
var binding = new Binding(nameof(TestClass.BoundValue), BindingMode.TwoWay) |
|||
{ |
|||
Source = instance |
|||
}; |
|||
|
|||
instance.Bind(TestClass.IntValueProperty, binding); |
|||
} |
|||
|
|||
[Benchmark] |
|||
public void UpdateTwoWayBinding_Via_Binding() |
|||
{ |
|||
var instance = new TestClass(); |
|||
|
|||
var binding = new Binding(nameof(TestClass.BoundValue), BindingMode.TwoWay) |
|||
{ |
|||
Source = instance |
|||
}; |
|||
|
|||
instance.Bind(TestClass.IntValueProperty, binding); |
|||
for (int i = 0; i < 60; i++) |
|||
{ |
|||
instance.IntValue = i; |
|||
} |
|||
} |
|||
private class TestClass : AvaloniaObject |
|||
{ |
|||
public static readonly StyledProperty<int> IntValueProperty = |
|||
AvaloniaProperty.Register<TestClass, int>(nameof(IntValue)); |
|||
|
|||
public static readonly StyledProperty<int> BoundValueProperty = |
|||
AvaloniaProperty.Register<TestClass, int>(nameof(BoundValue)); |
|||
|
|||
public int IntValue |
|||
{ |
|||
get => GetValue(IntValueProperty); |
|||
set => SetValue(IntValueProperty, value); |
|||
} |
|||
|
|||
public int BoundValue |
|||
{ |
|||
get => GetValue(BoundValueProperty); |
|||
set => SetValue(BoundValueProperty, value); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Avalonia.Controls; |
|||
using Avalonia.UnitTests; |
|||
using Avalonia.VisualTree; |
|||
using BenchmarkDotNet.Attributes; |
|||
|
|||
namespace Avalonia.Benchmarks.Traversal |
|||
{ |
|||
[MemoryDiagnoser] |
|||
public class VisualTreeTraversal |
|||
{ |
|||
private readonly TestRoot _root; |
|||
private readonly List<Control> _controls = new List<Control>(); |
|||
private readonly List<Control> _shuffledControls; |
|||
|
|||
public VisualTreeTraversal() |
|||
{ |
|||
var panel = new StackPanel(); |
|||
_root = new TestRoot { Child = panel, Renderer = new NullRenderer()}; |
|||
_controls.Add(panel); |
|||
_controls = ControlHierarchyCreator.CreateChildren(_controls, panel, 3, 5, 4); |
|||
|
|||
var random = new Random(1); |
|||
|
|||
_shuffledControls = _controls.OrderBy(r => random.Next()).ToList(); |
|||
|
|||
_root.LayoutManager.ExecuteInitialLayoutPass(_root); |
|||
} |
|||
|
|||
[Benchmark] |
|||
public void FindAncestorOfType_Linq() |
|||
{ |
|||
foreach (Control control in _controls) |
|||
{ |
|||
control.GetSelfAndVisualAncestors() |
|||
.OfType<TestRoot>() |
|||
.FirstOrDefault(); |
|||
} |
|||
} |
|||
|
|||
[Benchmark] |
|||
public void FindAncestorOfType_Optimized() |
|||
{ |
|||
foreach (Control control in _controls) |
|||
{ |
|||
control.FindAncestorOfType<TestRoot>(); |
|||
} |
|||
} |
|||
|
|||
[Benchmark] |
|||
public void FindCommonVisualAncestor() |
|||
{ |
|||
foreach (IVisual first in _controls) |
|||
{ |
|||
foreach (Control second in _shuffledControls) |
|||
{ |
|||
first.FindCommonVisualAncestor(second); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue