SameValueZeroComparer.cs 683 B

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