Bug 1321885 - Add Max() and Min() methods to TimeDuration. r=froydnj
MozReview-Commit-ID: 4WvRa3ZSrmP
--- 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.