Bug 1184043: P1. Ignore empty interval in intervalset. r=mattwoodrow
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 15 Jul 2015 20:17:27 +1000
changeset 253130 29f28c8cd976c13dd856f3b8251ff8e29f4a5b15
parent 253129 41fd23011c7208544652a858f2bea28696e98800
child 253131 a5c54b9ebb83a09dc93472aecde1fc442ea66161
push id29061
push userryanvm@gmail.com
push dateThu, 16 Jul 2015 18:53:45 +0000
treeherdermozilla-central@a0f4a688433d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1184043
milestone42.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 1184043: P1. Ignore empty interval in intervalset. r=mattwoodrow Add IntersectsStrict method.
dom/media/Intervals.h
--- a/dom/media/Intervals.h
+++ b/dom/media/Intervals.h
@@ -152,16 +152,21 @@ public:
   }
 
   bool Intersects(const SelfType& aOther) const
   {
     return (mStart - mFuzz < aOther.mEnd + aOther.mFuzz) &&
       (aOther.mStart - aOther.mFuzz < mEnd + mFuzz);
   }
 
+  bool IntersectsStrict(const SelfType& aOther) const
+  {
+    return mStart < aOther.mEnd && aOther.mStart < mEnd;
+  }
+
   // Same as Intersects, but including the boundaries.
   bool Touches(const SelfType& aOther) const
   {
     return (mStart - mFuzz <= aOther.mEnd + aOther.mFuzz) &&
       (aOther.mStart - aOther.mFuzz <= mEnd + mFuzz);
   }
 
   // Returns true if aOther is strictly to the right of this and contiguous.
@@ -303,24 +308,28 @@ public:
     this->~IntervalSet();
     new(this) IntervalSet(Move(aOther));
     return *this;
   }
 
   SelfType& operator= (const ElemType& aInterval)
   {
     mIntervals.Clear();
-    mIntervals.AppendElement(aInterval);
+    if (!aInterval.IsEmpty()) {
+      mIntervals.AppendElement(aInterval);
+    }
     return *this;
   }
 
   SelfType& operator= (ElemType&& aInterval)
   {
     mIntervals.Clear();
-    mIntervals.AppendElement(Move(aInterval));
+    if (!aInterval.IsEmpty()) {
+      mIntervals.AppendElement(Move(aInterval));
+    }
     return *this;
   }
 
   SelfType& Add(const SelfType& aIntervals)
   {
     mIntervals.AppendElements(aIntervals.mIntervals);
     Normalize();
     return *this;
@@ -458,17 +467,17 @@ public:
   // Mutate this TimeRange to be the intersection of this and aOther.
   SelfType& Intersection(const SelfType& aOther)
   {
     ContainerType intersection;
 
     const ContainerType& other = aOther.mIntervals;
     IndexType i = 0, j = 0;
     for (; i < mIntervals.Length() && j < other.Length();) {
-      if (mIntervals[i].Intersects(other[j])) {
+      if (mIntervals[i].IntersectsStrict(other[j])) {
         intersection.AppendElement(mIntervals[i].Intersection(other[j]));
       }
       if (mIntervals[i].mEnd < other[j].mEnd) {
         i++;
       } else {
         j++;
       }
     }