CallStackElementComparer.cs 985 B

12345678910111213141516171819202122232425262728293031323334
  1. #nullable enable
  2. using System.Collections.Generic;
  3. namespace Jint.Runtime.CallStack
  4. {
  5. internal sealed class CallStackElementComparer: IEqualityComparer<CallStackElement>
  6. {
  7. public static readonly CallStackElementComparer Instance = new();
  8. private CallStackElementComparer()
  9. {
  10. }
  11. public bool Equals(CallStackElement x, CallStackElement y)
  12. {
  13. if (x.Function._functionDefinition is not null)
  14. {
  15. return ReferenceEquals(x.Function._functionDefinition, y.Function._functionDefinition);
  16. }
  17. return ReferenceEquals(x.Function, y.Function);
  18. }
  19. public int GetHashCode(CallStackElement obj)
  20. {
  21. if (obj.Function._functionDefinition is not null)
  22. {
  23. return obj.Function._functionDefinition.GetHashCode();
  24. }
  25. return obj.Function.GetHashCode();
  26. }
  27. }
  28. }