Skip to content

Commit ee6392f

Browse files
authored
Merge pull request unoplatform#15538 from unoplatform/Youssef1313/ancestors-dict
perf: Make AncestorsDictionary a struct
2 parents 5b3af97 + d9e076e commit ee6392f

File tree

1 file changed

+26
-40
lines changed

1 file changed

+26
-40
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,41 @@
11
#nullable enable
22

33
using System;
4-
using Uno.UI.DataBinding;
5-
using System.Collections.Generic;
6-
using Uno.Extensions;
7-
using Uno.Foundation.Logging;
8-
using Uno.Diagnostics.Eventing;
9-
using Uno.Disposables;
10-
using System.Linq;
11-
using System.Threading;
124
using Uno.Collections;
13-
using System.Runtime.CompilerServices;
14-
using System.Diagnostics;
15-
using Microsoft.UI.Xaml.Data;
16-
using Uno.UI;
17-
using System.Collections;
18-
19-
#if __ANDROID__
20-
using View = Android.Views.View;
21-
#elif __IOS__
22-
using View = UIKit.UIView;
23-
#endif
24-
25-
namespace Microsoft.UI.Xaml
5+
6+
namespace Microsoft.UI.Xaml;
7+
8+
public partial class DependencyObjectStore : IDisposable
269
{
27-
public partial class DependencyObjectStore : IDisposable
10+
private readonly struct AncestorsDictionary
2811
{
29-
private class AncestorsDictionary
12+
private readonly HashtableEx _entries = new HashtableEx();
13+
14+
// Constructor to avoid:
15+
// error CS8983: A 'struct' with field initializers must include an explicitly declared constructor.
16+
public AncestorsDictionary()
3017
{
31-
private readonly HashtableEx _entries = new HashtableEx();
18+
}
3219

33-
internal bool TryGetValue(object key, out bool isAncestor)
20+
internal bool TryGetValue(object key, out bool isAncestor)
21+
{
22+
if (_entries.TryGetValue(key, out var value))
3423
{
35-
if (_entries.TryGetValue(key, out var value))
36-
{
37-
isAncestor = (bool)value!;
38-
return true;
39-
}
40-
41-
isAncestor = false;
42-
return false;
24+
isAncestor = (bool)value!;
25+
return true;
4326
}
4427

45-
internal void Set(object key, bool isAncestor)
46-
=> _entries[key] = isAncestor;
28+
isAncestor = false;
29+
return false;
30+
}
31+
32+
internal void Set(object key, bool isAncestor)
33+
=> _entries[key] = isAncestor;
4734

48-
internal void Clear()
49-
=> _entries.Clear();
35+
internal void Clear()
36+
=> _entries.Clear();
5037

51-
internal void Dispose()
52-
=> _entries.Dispose();
53-
}
38+
internal void Dispose()
39+
=> _entries.Dispose();
5440
}
5541
}

0 commit comments

Comments
 (0)