Bug 1321885 - Add Max() and Min() methods to TimeDuration. r=froydnj draft
authorBotond Ballo <botond@mozilla.com>
Wed, 27 Jul 2016 14:07:57 -0400
changeset 447177 d7433ab7cdb949194e494568f0bf94b91639e27e
parent 447176 bfa85d23df57c8a1db17c99b267667becc1c4afd
child 447178 7fc17e00fddbdbe4856c08a78729e8467a1f9571
push id38008
push userbballo@mozilla.com
push dateFri, 02 Dec 2016 22:13:11 +0000
reviewersfroydnj
bugs1321885
milestone53.0a1
Bug 1321885 - Add Max() and Min() methods to TimeDuration. r=froydnj 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.