Bug 1192791 - Disregard '-=' 2nd operand's fuzz, so that small intervals don't collapse when complementary interval set is built - r=jya
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 11 Aug 2015 18:03:56 +1000
changeset 291484 aab36e44ccf4e90cff2885db20034a17c7fcb6f9
parent 291483 6ddbdbd66174b8f70e1280e03367c683ea726370
child 291486 d82b5a78686a4f6630128fa7b999e0e343a9ef06
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1192791
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 1192791 - Disregard '-=' 2nd operand's fuzz, so that small intervals don't collapse when complementary interval set is built - r=jya
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);
 }