execution_context_priority.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/performance_manager/public/execution_context_priority/execution_context_priority.h"
  5. #include <cstring>
  6. namespace performance_manager {
  7. namespace execution_context_priority {
  8. int ReasonCompare(const char* reason1, const char* reason2) {
  9. if (reason1 == reason2)
  10. return 0;
  11. if (reason1 == nullptr)
  12. return -1;
  13. if (reason2 == nullptr)
  14. return 1;
  15. return ::strcmp(reason1, reason2);
  16. }
  17. /////////////////////////////////////////////////////////////////////
  18. // PriorityAndReason
  19. int PriorityAndReason::Compare(const PriorityAndReason& other) const {
  20. if (priority_ > other.priority_)
  21. return 1;
  22. if (priority_ < other.priority_)
  23. return -1;
  24. return ReasonCompare(reason_, other.reason_);
  25. }
  26. bool PriorityAndReason::operator==(const PriorityAndReason& other) const {
  27. return Compare(other) == 0;
  28. }
  29. bool PriorityAndReason::operator!=(const PriorityAndReason& other) const {
  30. return Compare(other) != 0;
  31. }
  32. bool PriorityAndReason::operator<=(const PriorityAndReason& other) const {
  33. return Compare(other) <= 0;
  34. }
  35. bool PriorityAndReason::operator>=(const PriorityAndReason& other) const {
  36. return Compare(other) >= 0;
  37. }
  38. bool PriorityAndReason::operator<(const PriorityAndReason& other) const {
  39. return Compare(other) < 0;
  40. }
  41. bool PriorityAndReason::operator>(const PriorityAndReason& other) const {
  42. return Compare(other) > 0;
  43. }
  44. } // namespace execution_context_priority
  45. } // namespace performance_manager