Bug 1321885 - Add Max() and Min() methods to TimeDuration. r=froydnj
authorBotond Ballo <botond@mozilla.com>
Wed, 27 Jul 2016 14:07:57 -0400
changeset 373495 c11569440ccc1e5410dfd1c31be411b3ef46cc03
parent 373494 f93bcba13541b6bb60b537f90805ade0d94fc4d6
child 373496 ec3c08351f9e283508524457577a92d18f85ddb7
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1321885
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.