From b8a9b0ac807e59d186fd8abb25e0afef04474b3a Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 19 Feb 2024 20:28:54 +0200 Subject: [PATCH 1/2] perf: Make AncestorsDictionary a struct --- ...pendencyObjectStore.AncestorsDictionary.cs | 62 +++++++------------ 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/DependencyObjectStore.AncestorsDictionary.cs b/src/Uno.UI/UI/Xaml/DependencyObjectStore.AncestorsDictionary.cs index 92214e5ca00d..524d9ebca563 100644 --- a/src/Uno.UI/UI/Xaml/DependencyObjectStore.AncestorsDictionary.cs +++ b/src/Uno.UI/UI/Xaml/DependencyObjectStore.AncestorsDictionary.cs @@ -1,55 +1,35 @@ #nullable enable using System; -using Uno.UI.DataBinding; -using System.Collections.Generic; -using Uno.Extensions; -using Uno.Foundation.Logging; -using Uno.Diagnostics.Eventing; -using Uno.Disposables; -using System.Linq; -using System.Threading; using Uno.Collections; -using System.Runtime.CompilerServices; -using System.Diagnostics; -using Microsoft.UI.Xaml.Data; -using Uno.UI; -using System.Collections; - -#if __ANDROID__ -using View = Android.Views.View; -#elif __IOS__ -using View = UIKit.UIView; -#endif - -namespace Microsoft.UI.Xaml + +namespace Microsoft.UI.Xaml; + +public partial class DependencyObjectStore : IDisposable { - public partial class DependencyObjectStore : IDisposable + private readonly struct AncestorsDictionary { - private class AncestorsDictionary - { - private readonly HashtableEx _entries = new HashtableEx(); + private readonly HashtableEx _entries = new HashtableEx(); - internal bool TryGetValue(object key, out bool isAncestor) + internal bool TryGetValue(object key, out bool isAncestor) + { + if (_entries.TryGetValue(key, out var value)) { - if (_entries.TryGetValue(key, out var value)) - { - isAncestor = (bool)value!; - return true; - } - - isAncestor = false; - return false; + isAncestor = (bool)value!; + return true; } - internal void Set(object key, bool isAncestor) - => _entries[key] = isAncestor; + isAncestor = false; + return false; + } - internal void Clear() - => _entries.Clear(); + internal void Set(object key, bool isAncestor) + => _entries[key] = isAncestor; - internal void Dispose() - => _entries.Dispose(); - } + internal void Clear() + => _entries.Clear(); + + internal void Dispose() + => _entries.Dispose(); } } From d9e076e1c66259675048faa73189cb48979420a6 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 20 Feb 2024 00:42:10 +0200 Subject: [PATCH 2/2] chore: Fix build --- .../UI/Xaml/DependencyObjectStore.AncestorsDictionary.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Uno.UI/UI/Xaml/DependencyObjectStore.AncestorsDictionary.cs b/src/Uno.UI/UI/Xaml/DependencyObjectStore.AncestorsDictionary.cs index 524d9ebca563..814cb1e1d636 100644 --- a/src/Uno.UI/UI/Xaml/DependencyObjectStore.AncestorsDictionary.cs +++ b/src/Uno.UI/UI/Xaml/DependencyObjectStore.AncestorsDictionary.cs @@ -11,6 +11,12 @@ private readonly struct AncestorsDictionary { private readonly HashtableEx _entries = new HashtableEx(); + // Constructor to avoid: + // error CS8983: A 'struct' with field initializers must include an explicitly declared constructor. + public AncestorsDictionary() + { + } + internal bool TryGetValue(object key, out bool isAncestor) { if (_entries.TryGetValue(key, out var value))