SameValueZeroComparer.cs 653 B

123456789101112131415161718192021222324
  1. using System.Runtime.CompilerServices;
  2. namespace Jint.Native;
  3. internal sealed class SameValueZeroComparer : IEqualityComparer<JsValue>
  4. {
  5. public static readonly SameValueZeroComparer Instance = new();
  6. bool IEqualityComparer<JsValue>.Equals(JsValue? x, JsValue? y)
  7. {
  8. return Equals(x, y);
  9. }
  10. public int GetHashCode(JsValue obj)
  11. {
  12. return obj.GetHashCode();
  13. }
  14. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  15. internal static bool Equals(JsValue? x, JsValue? y)
  16. {
  17. return x == y || x is JsNumber xNum && y is JsNumber yNum && double.IsNaN(xNum._value) && double.IsNaN(yNum._value);
  18. }
  19. }