Bug 1197145 - Added BaseTimeDuration::IsZero(), BaseTimeDuration::operator bool(), TimeStamp::operator bool(). r=nfroyd
authorGerald Squelart <gsquelart@mozilla.com>
Fri, 21 Aug 2015 05:36:00 -0400
changeset 258944 332b56e301156802f269ded2a557f50b762b3ef2
parent 258943 d9ac2969f3bb3fbd14d56a32c05bdf853b92ec9b
child 258945 2d2b71f2c970ca20bb2ea65f0c919b347db6864e
push id64086
push userryanvm@gmail.com
push dateSun, 23 Aug 2015 22:17:19 +0000
treeherdermozilla-inbound@8a585b9dd1db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs1197145
milestone43.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 1197145 - Added BaseTimeDuration::IsZero(), BaseTimeDuration::operator bool(), TimeStamp::operator bool(). r=nfroyd
mozglue/misc/TimeStamp.h
--- a/mozglue/misc/TimeStamp.h
+++ b/mozglue/misc/TimeStamp.h
@@ -253,16 +253,24 @@ public:
   {
     return mValue == aOther.mValue;
   }
   template<typename E>
   bool operator!=(const BaseTimeDuration<E>& aOther) const
   {
     return mValue != aOther.mValue;
   }
+  bool IsZero() const
+  {
+    return mValue == 0;
+  }
+  explicit operator bool() const
+  {
+    return mValue != 0;
+  }
 
   // Return a best guess at the system's current timing resolution,
   // which might be variable.  BaseTimeDurations below this order of
   // magnitude are meaningless, and those at the same order of
   // magnitude or just above are suspect.
   static BaseTimeDuration Resolution() {
     return FromTicks(BaseTimeDurationPlatformUtils::ResolutionInTicks());
   }
@@ -409,16 +417,25 @@ public:
 #endif
 
   /**
    * Return true if this is the "null" moment
    */
   bool IsNull() const { return mValue == 0; }
 
   /**
+   * Return true if this is not the "null" moment, may be used in tests, e.g.:
+   * |if (timestamp) { ... }|
+   */
+  explicit operator bool() const
+  {
+    return mValue != 0;
+  }
+
+  /**
    * Return a timestamp reflecting the current elapsed system time. This
    * is monotonically increasing (i.e., does not decrease) over the
    * lifetime of this process' XPCOM session.
    *
    * Now() is trying to ensure the best possible precision on each platform,
    * at least one millisecond.
    *
    * NowLoRes() has been introduced to workaround performance problems of