Add Max() and Min() methods to TimeDuration draft
authorBotond Ballo <botond@mozilla.com>
Wed, 27 Jul 2016 14:07:57 -0400
changeset 394552 bac442a609767fbb21b266dbd719d6eb968fbf3d
parent 394551 cf9177244f5930a4290cdc457ef701e2862f447c
child 394553 2830bdb39f5c9fa7446b30fe2a0b626c9ff1e8b7
push id24603
push userbballo@mozilla.com
push dateFri, 29 Jul 2016 23:28:33 +0000
milestone50.0a1
Add Max() and Min() methods to TimeDuration MozReview-Commit-ID: 4WvRa3ZSrmP
mozglue/misc/TimeStamp.h
--- a/mozglue/misc/TimeStamp.h
+++ b/mozglue/misc/TimeStamp.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_TimeStamp_h
 #define mozilla_TimeStamp_h
 
 #include <stdint.h>
+#include <algorithm>  // for std::min, std::max
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/TypeTraits.h"
 #include "mozilla/Types.h"
 
 namespace IPC {
 template<typename T> struct ParamTraits;
@@ -170,16 +171,27 @@ public:
       ticks = INT64_MAX;
     } else {
       ticks = -mValue;
     }
 
     return FromTicks(ticks);
   }
 
+  static BaseTimeDuration Max(const BaseTimeDuration& aA,
+                              const BaseTimeDuration& aB)
+  {
+    return FromTicks(std::max(aA.mValue, aB.mValue));
+  }
+  static BaseTimeDuration Min(const BaseTimeDuration& aA,
+                              const BaseTimeDuration& aB)
+  {
+    return FromTicks(std::min(aA.mValue, aB.mValue));
+  }
+
 private:
   // Block double multiplier (slower, imprecise if long duration) - Bug 853398.
   // If required, use MultDouble explicitly and with care.
   BaseTimeDuration operator*(const double aMultiplier) const = delete;
 
   // Block double divisor (for the same reason, and because dividing by
   // fractional values would otherwise invoke the int64_t variant, and rounding
   // the passed argument can then cause divide-by-zero) - Bug 1147491.