Bug 1031532 - Tighten up public interface of SourceBufferResource::ResourceQueue. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Mon, 14 Jul 2014 22:41:00 +1200
changeset 215904 cc69e484c0e10d5348287e2aa0f1aa587c134a16
parent 215903 82e387c007e395345f28868a949db4a00b824423
child 215905 73300964c5109ada8e009c77747bd232d85e4372
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1031532
milestone33.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 1031532 - Tighten up public interface of SourceBufferResource::ResourceQueue. r=cajbir
content/media/mediasource/SourceBufferResource.h
--- a/content/media/mediasource/SourceBufferResource.h
+++ b/content/media/mediasource/SourceBufferResource.h
@@ -67,81 +67,39 @@ private:
   class ResourceQueueDeallocator : public nsDequeFunctor {
     virtual void* operator() (void* anObject) {
       delete static_cast<ResourceItem*>(anObject);
       return nullptr;
     }
   };
 
   class ResourceQueue : private nsDeque {
-  private:
-    // Logical offset into the resource of the first element
-    // in the queue.
-    uint64_t mOffset;
-
   public:
     ResourceQueue() :
       nsDeque(new ResourceQueueDeallocator()),
       mOffset(0)
     {
     }
 
-    // Clears all items from the queue
-    inline void Clear() {
-      return nsDeque::Erase();
-    }
-
-    // Returns the number of items in the queue
-    inline uint32_t GetSize() {
-      return nsDeque::GetSize();
-    }
-
     // Returns the logical byte offset of the start of the data.
     inline uint64_t GetOffset() {
       return mOffset;
     }
 
-    inline ResourceItem* ResourceAt(uint32_t aIndex) {
-      return static_cast<ResourceItem*>(nsDeque::ObjectAt(aIndex));
-    }
-
     // Returns the length of all items in the queue plus the offset.
     // This is the logical length of the resource.
     inline uint64_t GetLength() {
       uint64_t s = mOffset;
       for (uint32_t i = 0; i < GetSize(); ++i) {
         ResourceItem* item = ResourceAt(i);
         s += item->mData.Length();
       }
       return s;
     }
 
-    // Returns the index of the resource that contains the given
-    // logical offset. aResourceOffset will contain the offset into
-    // the resource at the given index returned if it is not null.  If
-    // no such resource exists, returns GetSize() and aOffset is
-    // untouched.
-    inline uint32_t GetAtOffset(uint64_t aOffset, uint32_t *aResourceOffset) {
-      MOZ_ASSERT(aOffset >= mOffset);
-      uint64_t offset = mOffset;
-      for (uint32_t i = 0; i < GetSize(); ++i) {
-        ResourceItem* item = ResourceAt(i);
-        // If the item contains the start of the offset we want to
-        // break out of the loop.
-        if (item->mData.Length() + offset > aOffset) {
-          if (aResourceOffset) {
-            *aResourceOffset = aOffset - offset;
-          }
-          return i;
-        }
-        offset += item->mData.Length();
-      }
-      return GetSize();
-    }
-
     // Copies aCount bytes from aOffset in the queue into aDest.
     inline void CopyData(uint64_t aOffset, uint32_t aCount, char* aDest) {
       uint32_t offset = 0;
       uint32_t start = GetAtOffset(aOffset, &offset);
       uint32_t end = std::min(GetAtOffset(aOffset + aCount, nullptr) + 1, GetSize());
       for (uint32_t i = start; i < end; ++i) {
         ResourceItem* item = ResourceAt(i);
         uint32_t bytes = std::min(aCount, uint32_t(item->mData.Length() - offset));
@@ -153,28 +111,16 @@ private:
         }
       }
     }
 
     inline void PushBack(ResourceItem* aItem) {
       nsDeque::Push(aItem);
     }
 
-    inline void PushFront(ResourceItem* aItem) {
-      nsDeque::PushFront(aItem);
-    }
-
-    inline ResourceItem* PopBack() {
-      return static_cast<ResourceItem*>(nsDeque::Pop());
-    }
-
-    inline ResourceItem* PopFront() {
-      return static_cast<ResourceItem*>(nsDeque::PopFront());
-    }
-
     // Evict data in queue if the total queue size is greater than
     // aThreshold past the offset. Returns true if some data was
     // actually evicted.
     inline bool Evict(uint64_t aOffset, uint32_t aThreshold) {
       bool evicted = false;
       while (GetLength() - mOffset > aThreshold) {
         ResourceItem* item = ResourceAt(0);
         if (item->mData.Length() + mOffset > aOffset) {
@@ -195,16 +141,57 @@ private:
       for (int32_t i = 0; i < nsDeque::GetSize(); ++i) {
         const ResourceItem* item =
             static_cast<const ResourceItem*>(nsDeque::ObjectAt(i));
         size += item->SizeOfIncludingThis(aMallocSizeOf);
       }
 
       return size;
     }
+
+  private:
+    // Returns the number of items in the queue
+    inline uint32_t GetSize() {
+      return nsDeque::GetSize();
+    }
+
+    inline ResourceItem* ResourceAt(uint32_t aIndex) {
+      return static_cast<ResourceItem*>(nsDeque::ObjectAt(aIndex));
+    }
+
+    // Returns the index of the resource that contains the given
+    // logical offset. aResourceOffset will contain the offset into
+    // the resource at the given index returned if it is not null.  If
+    // no such resource exists, returns GetSize() and aOffset is
+    // untouched.
+    inline uint32_t GetAtOffset(uint64_t aOffset, uint32_t *aResourceOffset) {
+      MOZ_ASSERT(aOffset >= mOffset);
+      uint64_t offset = mOffset;
+      for (uint32_t i = 0; i < GetSize(); ++i) {
+        ResourceItem* item = ResourceAt(i);
+        // If the item contains the start of the offset we want to
+        // break out of the loop.
+        if (item->mData.Length() + offset > aOffset) {
+          if (aResourceOffset) {
+            *aResourceOffset = aOffset - offset;
+          }
+          return i;
+        }
+        offset += item->mData.Length();
+      }
+      return GetSize();
+    }
+
+    inline ResourceItem* PopFront() {
+      return static_cast<ResourceItem*>(nsDeque::PopFront());
+    }
+
+    // Logical offset into the resource of the first element
+    // in the queue.
+    uint64_t mOffset;
   };
 
 public:
   SourceBufferResource(nsIPrincipal* aPrincipal,
                        const nsACString& aType);
   ~SourceBufferResource();
 
   virtual nsresult Close() MOZ_OVERRIDE;