Skip to content

Commit ff270fc

Browse files
committed
PR feedback
1 parent 0e9185e commit ff270fc

File tree

3 files changed

+39
-44
lines changed

3 files changed

+39
-44
lines changed

src/Grpc.Net.Client/Balancer/BalancerAttributes.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public sealed class BalancerAttributes : IDictionary<string, object?>, IReadOnly
4040
/// </summary>
4141
public static readonly BalancerAttributes Empty = new BalancerAttributes(new Dictionary<string, object?>(), readOnly: true);
4242

43-
internal readonly Dictionary<string, object?> _attributes;
43+
private readonly Dictionary<string, object?> _attributes;
4444
private readonly bool _readOnly;
4545

4646
/// <summary>
@@ -171,6 +171,42 @@ private void ValidateReadOnly()
171171
}
172172
}
173173

174+
internal static bool DeepEquals(BalancerAttributes? x, BalancerAttributes? y)
175+
{
176+
var xValues = x?._attributes;
177+
var yValues = y?._attributes;
178+
179+
if (ReferenceEquals(xValues, yValues))
180+
{
181+
return true;
182+
}
183+
184+
if (xValues == null || yValues == null)
185+
{
186+
return false;
187+
}
188+
189+
if (xValues.Count != yValues.Count)
190+
{
191+
return false;
192+
}
193+
194+
foreach (var kvp in xValues)
195+
{
196+
if (!yValues.TryGetValue(kvp.Key, out var value))
197+
{
198+
return false;
199+
}
200+
201+
if (!Equals(kvp.Value, value))
202+
{
203+
return false;
204+
}
205+
}
206+
207+
return true;
208+
}
209+
174210
private string DebuggerToString()
175211
{
176212
return $"Count = {_attributes.Count}";

src/Grpc.Net.Client/Balancer/Internal/BalancerAddressEqualityComparer.cs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#endregion
1818

1919
#if SUPPORT_LOAD_BALANCING
20-
using System;
21-
using System.Collections.Generic;
2220
using System.Diagnostics.CodeAnalysis;
2321

2422
namespace Grpc.Net.Client.Balancer.Internal;
@@ -44,47 +42,7 @@ public bool Equals(BalancerAddress? x, BalancerAddress? y)
4442
return false;
4543
}
4644

47-
var xAttributes = x._attributes?._attributes;
48-
var yAttributes = y._attributes?._attributes;
49-
if (!AttributesEqual(xAttributes, yAttributes))
50-
{
51-
return false;
52-
}
53-
54-
return true;
55-
}
56-
57-
private bool AttributesEqual(Dictionary<string, object?>? x, Dictionary<string, object?>? y)
58-
{
59-
if (x == null && y == null)
60-
{
61-
return true;
62-
}
63-
64-
if (x == null || y == null)
65-
{
66-
return false;
67-
}
68-
69-
if (x.Count != y.Count)
70-
{
71-
return false;
72-
}
73-
74-
foreach (var kvp in x)
75-
{
76-
if (!y.TryGetValue(kvp.Key, out var value))
77-
{
78-
return false;
79-
}
80-
81-
if (!Equals(kvp.Value, value))
82-
{
83-
return false;
84-
}
85-
}
86-
87-
return true;
45+
return BalancerAttributes.DeepEquals(x._attributes, y._attributes);
8846
}
8947

9048
public int GetHashCode([DisallowNull] BalancerAddress obj)

src/Grpc.Net.Client/Balancer/Subchannel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#endregion
1818

1919
#if SUPPORT_LOAD_BALANCING
20+
using System.Net;
2021
using Grpc.Core;
2122
using Grpc.Net.Client.Balancer.Internal;
2223
using Microsoft.Extensions.Logging;

0 commit comments

Comments
 (0)