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 259906 ca8eaf3366e5c74341ba5e3a96813afd0639746c
parent 259905 d3e9b16fc53f07ebbf6248e29366a6bd2714c54d
child 259907 5f5a4c5a7e021a0f9edc72f39a7292bd97187918
push id721
push userjlund@mozilla.com
push dateTue, 21 Apr 2015 23:03:33 +0000
treeherdermozilla-release@d27c9211ebb3 [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();
   }