Skip to content

Commit

Permalink
Use explicit comparer for extension identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
ObsidianMinor committed Dec 2, 2019
1 parent 145033c commit 34f9497
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions csharp/src/Google.Protobuf/ExtensionRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ namespace Google.Protobuf
/// </summary>
public sealed class ExtensionRegistry : ICollection<Extension>, IDeepCloneable<ExtensionRegistry>
{
internal sealed class ExtensionComparer : IEqualityComparer<Extension>
{
public bool Equals(Extension a, Extension b)
{
return new ObjectIntPair<Type>(a.TargetType, a.FieldNumber).Equals(new ObjectIntPair<Type>(b.TargetType, b.FieldNumber));
}
public int GetHashCode(Extension a)
{
return new ObjectIntPair<Type>(a.TargetType, a.FieldNumber).GetHashCode();
}

internal static ExtensionComparer Instance = new ExtensionComparer();
}
private IDictionary<ObjectIntPair<Type>, Extension> extensions;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private void CrossLink()

private static IEnumerable<Extension> GetAllExtensions(FileDescriptor[] dependencies, GeneratedClrTypeInfo generatedInfo)
{
return dependencies.SelectMany(GetAllDependedExtensions).Distinct().Concat(GetAllGeneratedExtensions(generatedInfo));
return dependencies.SelectMany(GetAllDependedExtensions).Distinct(ExtensionRegistry.ExtensionComparer.Instance).Concat(GetAllGeneratedExtensions(generatedInfo));
}

private static IEnumerable<Extension> GetAllGeneratedExtensions(GeneratedClrTypeInfo generated)
Expand Down

0 comments on commit 34f9497

Please sign in to comment.