Bug 1148684 - Compact SourceBuffer even if it contains only one chunk. r=tn, a=sledru
authorSeth Fowler <mark.seth.fowler@gmail.com>
Sun, 29 Mar 2015 16:25:15 -0700
changeset 258247 ca8eaf3366e5
parent 258246 d3e9b16fc53f
child 258248 5f5a4c5a7e02
push id4627
push userryanvm@gmail.com
push date2015-04-03 19:22 +0000
treeherdermozilla-beta@5f5a4c5a7e02 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn, sledru
bugs1148684
milestone38.0
Bug 1148684 - Compact SourceBuffer even if it contains only one chunk. r=tn, a=sledru
image/src/SourceBuffer.cpp
--- a/image/src/SourceBuffer.cpp
+++ b/image/src/SourceBuffer.cpp
@@ -116,18 +116,23 @@ SourceBuffer::Compact()
   MOZ_ASSERT(mConsumerCount == 0, "Should have no consumers here");
   MOZ_ASSERT(mWaitingConsumers.Length() == 0, "Shouldn't have waiters");
   MOZ_ASSERT(mStatus, "Should be complete here");
 
   // Compact our waiting consumers list, since we're complete and no future
   // consumer will ever have to wait.
   mWaitingConsumers.Compact();
 
-  // If we have no more than one chunk, then we can't compact further.
-  if (mChunks.Length() < 2) {
+  // If we have no chunks, then there's nothing to compact.
+  if (mChunks.Length() < 1) {
+    return NS_OK;
+  }
+
+  // If we have one chunk, then we can compact if it has excess capacity.
+  if (mChunks.Length() == 1 && mChunks[0].Length() == mChunks[0].Capacity()) {
     return NS_OK;
   }
 
   // We can compact our buffer. Determine the total length.
   size_t length = 0;
   for (uint32_t i = 0 ; i < mChunks.Length() ; ++i) {
     length += mChunks[i].Length();
   }