Skip to content

Commit

Permalink
Keep byte[] code-path for maximum efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
h3xds1nz committed Jan 23, 2025
1 parent e7f2a6f commit 8c6e0ca
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/ReflectionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

using System.Runtime.CompilerServices;
using System.Reflection.Metadata;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System;
using System.Diagnostics;

namespace MS.Internal
{
Expand Down Expand Up @@ -126,6 +125,20 @@ internal static void GetAssemblyVersionPlusToken(Assembly assembly, out ReadOnly
}
}

/// <summary>
/// Compares whether two PublicKeyTokens are the same.
/// If both <paramref name="reqToken"/> and <paramref name="curToken"/> are <see langword="null"/>, <see langword="true"/> is returned.
/// </summary>
/// <param name="reqToken">First PublicKeyToken to compare.</param>
/// <param name="curToken">Second PublicKeyToken to compare.</param>
/// <returns><see langword="true"/> if both parameters are <see langword="null"/> or equal in sequence, <see langword="false"/> otherwise.</returns>
internal static bool IsSamePublicKeyToken(byte[] reqToken, byte[] curToken)
{
Debug.Assert((reqToken is null || reqToken.Length is 0 or 8) && (curToken is null || curToken.Length is 0 or 8), "Provided PublicKeyToken has invalid length");

return (reqToken is null && curToken is null) || (curToken is not null && reqToken is not null && reqToken.AsSpan().SequenceEqual(curToken));
}

/// <summary>
/// Compares whether two PublicKeyTokens are the same.
/// If both <paramref name="reqToken"/> and <paramref name="curToken"/> are <see cref="ReadOnlySpan{byte}.Empty"/>, <see langword="true"/> is returned.
Expand Down

0 comments on commit 8c6e0ca

Please sign in to comment.