Bug 1552712 - Reserve upper bound for capacity of IntervalSet::Intersection(). r=jya
authorChris Pearce <cpearce@mozilla.com>
Tue, 21 May 2019 17:09:53 +0000
changeset 474821 96306b575252ae9f2914a5ca3c92f84356031a94
parent 474820 9ee0f79d80d1a777869ec7dd2774694a0bef86f8
child 474822 350f7249407d5156f831562b38807111790e8e74
push id86000
push usercpearce@mozilla.com
push dateTue, 21 May 2019 17:42:50 +0000
treeherderautoland@96306b575252 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1552712
milestone69.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 1552712 - Reserve upper bound for capacity of IntervalSet::Intersection(). r=jya Previous patch in Bug 1552712 actually didn't set the correct upper bound; it failed to set the upper bound in cases like: intersect({[0,10]}, {[0,1], [2,3], [4,5]}) That's clearly the maximum of the lengths of the array, not the minimum. Differential Revision: https://phabricator.services.mozilla.com/D31946
dom/media/Intervals.h
--- a/dom/media/Intervals.h
+++ b/dom/media/Intervals.h
@@ -426,17 +426,17 @@ class IntervalSet {
 
   // Mutate this TimeRange to be the intersection of this and aOther.
   SelfType& Intersection(const SelfType& aOther) {
     ContainerType intersection;
 
     // Ensure the intersection has enough capacity to store the upper bound on
     // the intersection size. This ensures that we don't spend time reallocating
     // the storage as we append, at the expense of extra memory.
-    intersection.SetCapacity(std::min(aOther.Length(), mIntervals.Length()));
+    intersection.SetCapacity(std::max(aOther.Length(), mIntervals.Length()));
 
     const ContainerType& other = aOther.mIntervals;
     IndexType i = 0, j = 0;
     for (; i < mIntervals.Length() && j < other.Length();) {
       if (mIntervals[i].IntersectsStrict(other[j])) {
         intersection.AppendElement(mIntervals[i].Intersection(other[j]));
       }
       if (mIntervals[i].mEnd < other[j].mEnd) {