Bug 1039924 part 2 - Convert between Forever and Infinity when converting TimeDurations; r=froydnj
authorBrian Birtles <birtles@gmail.com>
Thu, 25 Sep 2014 14:25:49 +0900
changeset 230365 cef7118a25cb3dfb378eb46eb7e01201e44948e0
parent 230364 dc77f42529f7b494895c19365939f400b7176b62
child 230366 af942cc33a8385e684ecc850f74af424482211b3
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1039924
milestone35.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 1039924 part 2 - Convert between Forever and Infinity when converting TimeDurations; r=froydnj Now that the implementation of a number of TimeDuration methods have been delegated to a separate TimeDurationPlatformUtils class, it is easier to add consistent handling to the parameters passed to and from those methods. This patch adds checks when converting between TimeDurations and doubles so that Forever (represented by a tick count of INT64_MAX) is paired with PositiveInfinity, and INT64_MIN is paired with NegativeInfinity.
xpcom/ds/TimeStamp.h
--- a/xpcom/ds/TimeStamp.h
+++ b/xpcom/ds/TimeStamp.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_TimeStamp_h
 #define mozilla_TimeStamp_h
 
 #include <stdint.h>
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/FloatingPoint.h"
 #include "nscore.h"
 #include "nsDebug.h"
 
 namespace IPC {
 template<typename T> struct ParamTraits;
 }
 
 #ifdef XP_WIN
@@ -64,39 +65,57 @@ public:
   MOZ_IMPLICIT TimeDuration(_SomethingVeryRandomHere* aZero) : mValue(0)
   {
     MOZ_ASSERT(!aZero, "Who's playing funny games here?");
   }
   // Default copy-constructor and assignment are OK
 
   double ToSeconds() const
   {
+    if (mValue == INT64_MAX) {
+      return PositiveInfinity<double>();
+    }
+    if (mValue == INT64_MIN) {
+      return NegativeInfinity<double>();
+    }
     return TimeDurationPlatformUtils::ToSeconds(mValue);
   }
   // Return a duration value that includes digits of time we think to
   // be significant.  This method should be used when displaying a
   // time to humans.
   double ToSecondsSigDigits() const
   {
+    if (mValue == INT64_MAX) {
+      return PositiveInfinity<double>();
+    }
+    if (mValue == INT64_MIN) {
+      return NegativeInfinity<double>();
+    }
     return TimeDurationPlatformUtils::ToSecondsSigDigits(mValue);
   }
   double ToMilliseconds() const { return ToSeconds() * 1000.0; }
   double ToMicroseconds() const { return ToMilliseconds() * 1000.0; }
 
   // Using a double here is safe enough; with 53 bits we can represent
   // durations up to over 280,000 years exactly.  If the units of
   // mValue do not allow us to represent durations of that length,
   // long durations are clamped to the max/min representable value
   // instead of overflowing.
   static inline TimeDuration FromSeconds(double aSeconds)
   {
     return FromMilliseconds(aSeconds * 1000.0);
   }
   static TimeDuration FromMilliseconds(double aMilliseconds)
   {
+    if (aMilliseconds == PositiveInfinity<double>()) {
+      return Forever();
+    }
+    if (aMilliseconds == NegativeInfinity<double>()) {
+      return FromTicks(INT64_MIN);
+    }
     return FromTicks(
       TimeDurationPlatformUtils::TicksFromMilliseconds(aMilliseconds));
   }
   static inline TimeDuration FromMicroseconds(double aMicroseconds)
   {
     return FromMilliseconds(aMicroseconds / 1000.0);
   }