Bug 1192791 - Disregard '-=' 2nd operand's fuzz, so that small intervals don't collapse when complementary interval set is built. r=jya, a=sledru
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 11 Aug 2015 18:03:56 +1000
changeset 277157 c138c6fff215a8210d2832b11bc3094feb6ff61c
parent 277156 c1afd8bcd6922b5f266d388b2af4ed5fb21a1182
child 277158 1cfe65791f1cf67f5427eb63888b550ca99b984b
push id8323
push userryanvm@gmail.com
push dateMon, 17 Aug 2015 21:43:32 +0000
treeherdermozilla-aurora@ebcd3c379b1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya, sledru
bugs1192791
milestone42.0a2
Bug 1192791 - Disregard '-=' 2nd operand's fuzz, so that small intervals don't collapse when complementary interval set is built. r=jya, a=sledru
dom/media/Intervals.h
dom/media/gtest/TestIntervalSet.cpp
--- a/dom/media/Intervals.h
+++ b/dom/media/Intervals.h
@@ -424,18 +424,18 @@ public:
   // and then doing the intersection.
   SelfType& operator-= (const ElemType& aInterval)
   {
     if (aInterval.IsEmpty() || mIntervals.IsEmpty()) {
       return *this;
     }
     T firstEnd = std::max(mIntervals[0].mStart, aInterval.mStart);
     T secondStart = std::min(mIntervals.LastElement().mEnd, aInterval.mEnd);
-    ElemType startInterval(mIntervals[0].mStart, firstEnd, aInterval.mFuzz);
-    ElemType endInterval(secondStart, mIntervals.LastElement().mEnd, aInterval.mFuzz);
+    ElemType startInterval(mIntervals[0].mStart, firstEnd);
+    ElemType endInterval(secondStart, mIntervals.LastElement().mEnd);
     SelfType intervals(Move(startInterval));
     intervals += Move(endInterval);
     return Intersection(intervals);
   }
 
   SelfType& operator-= (const SelfType& aIntervals)
   {
     for (const auto& interval : aIntervals.mIntervals) {
--- a/dom/media/gtest/TestIntervalSet.cpp
+++ b/dom/media/gtest/TestIntervalSet.cpp
@@ -771,9 +771,51 @@ TEST(IntervalSet, Substraction)
   i0 += IntInterval(5, 10);
   i0 += IntInterval(20, 25);
   i0 += IntInterval(40, 60);
   i1 = IntInterval(8, 70);
   i0 -= i1;
   EXPECT_EQ(1u, i0.Length());
   EXPECT_EQ(5, i0[0].mStart);
   EXPECT_EQ(8, i0[0].mEnd);
+
+  i0 = IntIntervals();
+  i0 += IntInterval(0, 10);
+  IntIntervals i2;
+  i2 += IntInterval(4, 6);
+  i0 -= i2;
+  EXPECT_EQ(2u, i0.Length());
+  EXPECT_EQ(0, i0[0].mStart);
+  EXPECT_EQ(4, i0[0].mEnd);
+  EXPECT_EQ(6, i0[1].mStart);
+  EXPECT_EQ(10, i0[1].mEnd);
+
+  i0 = IntIntervals();
+  i0 += IntInterval(0, 1);
+  i0 += IntInterval(3, 10);
+  EXPECT_EQ(2u, i0.Length());
+  // This fuzz should collapse i0 into [0,10).
+  i0.SetFuzz(1);
+  EXPECT_EQ(1u, i0.Length());
+  EXPECT_EQ(1, i0[0].mFuzz);
+  i2 = IntInterval(4, 6);
+  i0 -= i2;
+  EXPECT_EQ(2u, i0.Length());
+  EXPECT_EQ(0, i0[0].mStart);
+  EXPECT_EQ(4, i0[0].mEnd);
+  EXPECT_EQ(6, i0[1].mStart);
+  EXPECT_EQ(10, i0[1].mEnd);
+  EXPECT_EQ(1, i0[0].mFuzz);
+  EXPECT_EQ(1, i0[1].mFuzz);
+
+  i0 = IntIntervals();
+  i0 += IntInterval(0, 10);
+  // [4,6) with fuzz 1 used to fail because the complementary interval set
+  // [0,4)+[6,10) would collapse into [0,10).
+  i2 = IntInterval(4, 6);
+  i2.SetFuzz(1);
+  i0 -= i2;
+  EXPECT_EQ(2u, i0.Length());
+  EXPECT_EQ(0, i0[0].mStart);
+  EXPECT_EQ(4, i0[0].mEnd);
+  EXPECT_EQ(6, i0[1].mStart);
+  EXPECT_EQ(10, i0[1].mEnd);
 }