Bug 1148684 - Compact SourceBuffer even if it contains only one chunk. r=tn
authorSeth Fowler <mark.seth.fowler@gmail.com>
Sun, 29 Mar 2015 16:25:15 -0700
changeset 265296 f64b5c0ee649a2e2ade9ed95c59fe4698296d76d
parent 265295 861900f9685a29e1f527c8f66c96b135e238ab6d
child 265297 5b72da096a3cbd0ef7917f5a9ba6a2a2caeb01d5
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs1148684
milestone39.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 1148684 - Compact SourceBuffer even if it contains only one chunk. r=tn
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();
   }