|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using Avalonia.Controls; |
|
|
|
using System; |
|
|
|
using Avalonia.Controls; |
|
|
|
using Avalonia.Styling; |
|
|
|
using BenchmarkDotNet.Attributes; |
|
|
|
|
|
|
|
@ -11,6 +12,8 @@ namespace Avalonia.Benchmarks.Styling |
|
|
|
private readonly Calendar _matchingControl; |
|
|
|
private readonly Selector _isCalendarSelector; |
|
|
|
private readonly Selector _classSelector; |
|
|
|
private readonly Selector _orSelectorTwo; |
|
|
|
private readonly Selector _orSelectorFive; |
|
|
|
|
|
|
|
public SelectorBenchmark() |
|
|
|
{ |
|
|
|
@ -23,6 +26,14 @@ namespace Avalonia.Benchmarks.Styling |
|
|
|
|
|
|
|
_isCalendarSelector = Selectors.Is<Calendar>(null); |
|
|
|
_classSelector = Selectors.Class(null, className); |
|
|
|
|
|
|
|
_orSelectorTwo = Selectors.Or(new AlwaysMatchSelector(), new AlwaysMatchSelector()); |
|
|
|
_orSelectorFive = Selectors.Or( |
|
|
|
new AlwaysMatchSelector(), |
|
|
|
new AlwaysMatchSelector(), |
|
|
|
new AlwaysMatchSelector(), |
|
|
|
new AlwaysMatchSelector(), |
|
|
|
new AlwaysMatchSelector()); |
|
|
|
} |
|
|
|
|
|
|
|
[Benchmark] |
|
|
|
@ -48,5 +59,40 @@ namespace Avalonia.Benchmarks.Styling |
|
|
|
{ |
|
|
|
return _classSelector.Match(_matchingControl); |
|
|
|
} |
|
|
|
|
|
|
|
[Benchmark] |
|
|
|
public SelectorMatch OrSelector_One_Match() |
|
|
|
{ |
|
|
|
return _orSelectorTwo.Match(_matchingControl); |
|
|
|
} |
|
|
|
|
|
|
|
[Benchmark] |
|
|
|
public SelectorMatch OrSelector_Five_Match() |
|
|
|
{ |
|
|
|
return _orSelectorFive.Match(_matchingControl); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
internal class AlwaysMatchSelector : Selector |
|
|
|
{ |
|
|
|
public override bool InTemplate => false; |
|
|
|
|
|
|
|
public override bool IsCombinator => false; |
|
|
|
|
|
|
|
public override Type TargetType => null; |
|
|
|
|
|
|
|
public override string ToString(Style owner) |
|
|
|
{ |
|
|
|
return "Always"; |
|
|
|
} |
|
|
|
|
|
|
|
protected override SelectorMatch Evaluate(StyledElement control, IStyle parent, bool subscribe) |
|
|
|
{ |
|
|
|
return SelectorMatch.AlwaysThisType; |
|
|
|
} |
|
|
|
|
|
|
|
protected override Selector MovePrevious() => null; |
|
|
|
|
|
|
|
protected override Selector MovePreviousOrParent() => null; |
|
|
|
} |
|
|
|
} |
|
|
|
|