From ba4bfc36f82bc16e8d5201dbed861bc82d109545 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 17 Oct 2022 11:45:19 +0200 Subject: [PATCH] Go direct to ValueStore for untyped GetValue. Avoids a virtual call in the case of styled properties. --- src/Avalonia.Base/AvaloniaObject.cs | 10 +++++++++- src/Avalonia.Base/PropertyStore/ValueStore.cs | 2 -- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Base/AvaloniaObject.cs b/src/Avalonia.Base/AvaloniaObject.cs index 72a3fbe925..2bac41ea00 100644 --- a/src/Avalonia.Base/AvaloniaObject.cs +++ b/src/Avalonia.Base/AvaloniaObject.cs @@ -206,7 +206,15 @@ namespace Avalonia /// /// The property. /// The value. - public object? GetValue(AvaloniaProperty property) => property.RouteGetValue(this); + public object? GetValue(AvaloniaProperty property) + { + _ = property ?? throw new ArgumentNullException(nameof(property)); + + if (property.IsDirect) + return property.RouteGetValue(this); + else + return _values.GetValue(property); + } /// /// Gets a value. diff --git a/src/Avalonia.Base/PropertyStore/ValueStore.cs b/src/Avalonia.Base/PropertyStore/ValueStore.cs index ff1138ec1c..a99955eb07 100644 --- a/src/Avalonia.Base/PropertyStore/ValueStore.cs +++ b/src/Avalonia.Base/PropertyStore/ValueStore.cs @@ -2,12 +2,10 @@ using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using Avalonia.Collections.Pooled; using Avalonia.Data; using Avalonia.Diagnostics; using Avalonia.Logging; using Avalonia.Utilities; -using JetBrains.Annotations; namespace Avalonia.PropertyStore {