Bug 1397128 P2 Refactor StreamList::Add() to use move constructors and accept a nullptr stream. r=tt
☠☠ backed out by c0a6198c2345 ☠ ☠
authorBen Kelly <ben@wanderview.com>
Fri, 15 Sep 2017 09:11:22 -0700
changeset 381160 15edfaab92f6d812256252e8efc6b8574cd7c381
parent 381159 3f1e68da9634ed661ff2b4b1b128c43bf3e831bb
child 381161 bfbcc07fcb4bdb198e42424702c90d128c0ffaa7
push id32512
push userarchaeopteryx@coole-files.de
push dateFri, 15 Sep 2017 19:33:47 +0000
treeherdermozilla-central@6be5c7d30d2d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstt
bugs1397128
milestone57.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 1397128 P2 Refactor StreamList::Add() to use move constructors and accept a nullptr stream. r=tt
dom/cache/Manager.cpp
dom/cache/StreamList.cpp
dom/cache/StreamList.h
--- a/dom/cache/Manager.cpp
+++ b/dom/cache/Manager.cpp
@@ -543,17 +543,17 @@ public:
       return rv;
     }
 
     nsCOMPtr<nsIInputStream> stream;
     rv = BodyOpen(aQuotaInfo, aDBDir, mResponse.mBodyId, getter_AddRefs(stream));
     if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
     if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; }
 
-    mStreamList->Add(mResponse.mBodyId, stream);
+    mStreamList->Add(mResponse.mBodyId, Move(stream));
 
     return rv;
   }
 
   virtual void
   Complete(Listener* aListener, ErrorResult&& aRv) override
   {
     if (!mFoundResponse) {
@@ -609,17 +609,17 @@ public:
       }
 
       nsCOMPtr<nsIInputStream> stream;
       rv = BodyOpen(aQuotaInfo, aDBDir, mSavedResponses[i].mBodyId,
                     getter_AddRefs(stream));
       if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
       if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; }
 
-      mStreamList->Add(mSavedResponses[i].mBodyId, stream);
+      mStreamList->Add(mSavedResponses[i].mBodyId, Move(stream));
     }
 
     return rv;
   }
 
   virtual void
   Complete(Listener* aListener, ErrorResult&& aRv) override
   {
@@ -1157,17 +1157,17 @@ public:
       }
 
       nsCOMPtr<nsIInputStream> stream;
       rv = BodyOpen(aQuotaInfo, aDBDir, mSavedRequests[i].mBodyId,
                     getter_AddRefs(stream));
       if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
       if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; }
 
-      mStreamList->Add(mSavedRequests[i].mBodyId, stream);
+      mStreamList->Add(mSavedRequests[i].mBodyId, Move(stream));
     }
 
     return rv;
   }
 
   virtual void
   Complete(Listener* aListener, ErrorResult&& aRv) override
   {
@@ -1221,17 +1221,17 @@ public:
     }
 
     nsCOMPtr<nsIInputStream> stream;
     rv = BodyOpen(aQuotaInfo, aDBDir, mSavedResponse.mBodyId,
                   getter_AddRefs(stream));
     if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
     if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; }
 
-    mStreamList->Add(mSavedResponse.mBodyId, stream);
+    mStreamList->Add(mSavedResponse.mBodyId, Move(stream));
 
     return rv;
   }
 
   virtual void
   Complete(Listener* aListener, ErrorResult&& aRv) override
   {
     if (!mFoundResponse) {
--- a/dom/cache/StreamList.cpp
+++ b/dom/cache/StreamList.cpp
@@ -65,25 +65,22 @@ StreamList::Activate(CacheId aCacheId)
   mManager->AddStreamList(this);
 
   for (uint32_t i = 0; i < mList.Length(); ++i) {
     mManager->AddRefBodyId(mList[i].mId);
   }
 }
 
 void
-StreamList::Add(const nsID& aId, nsIInputStream* aStream)
+StreamList::Add(const nsID& aId, nsCOMPtr<nsIInputStream>&& aStream)
 {
   // All streams should be added on IO thread before we set the stream
   // control on the owning IPC thread.
   MOZ_DIAGNOSTIC_ASSERT(!mStreamControl);
-  MOZ_DIAGNOSTIC_ASSERT(aStream);
-  Entry* entry = mList.AppendElement();
-  entry->mId = aId;
-  entry->mStream = aStream;
+  mList.AppendElement(Entry(aId, Move(aStream)));
 }
 
 already_AddRefed<nsIInputStream>
 StreamList::Extract(const nsID& aId)
 {
   NS_ASSERT_OWNINGTHREAD(StreamList);
   for (uint32_t i = 0; i < mList.Length(); ++i) {
     if (mList[i].mId == aId) {
--- a/dom/cache/StreamList.h
+++ b/dom/cache/StreamList.h
@@ -26,32 +26,37 @@ class StreamList final : public Context:
 public:
   StreamList(Manager* aManager, Context* aContext);
 
   void SetStreamControl(CacheStreamControlParent* aStreamControl);
   void RemoveStreamControl(CacheStreamControlParent* aStreamControl);
 
   void Activate(CacheId aCacheId);
 
-  void Add(const nsID& aId, nsIInputStream* aStream);
+  void Add(const nsID& aId, nsCOMPtr<nsIInputStream>&& aStream);
   already_AddRefed<nsIInputStream> Extract(const nsID& aId);
 
   void NoteClosed(const nsID& aId);
   void NoteClosedAll();
   void Close(const nsID& aId);
   void CloseAll();
 
   // Context::Activity methods
   virtual void Cancel() override;
   virtual bool MatchesCacheId(CacheId aCacheId) const override;
 
 private:
   ~StreamList();
   struct Entry
   {
+    explicit Entry(const nsID& aId, nsCOMPtr<nsIInputStream>&& aStream)
+      : mId(aId)
+      , mStream(Move(aStream))
+    {}
+
     nsID mId;
     nsCOMPtr<nsIInputStream> mStream;
   };
   RefPtr<Manager> mManager;
   RefPtr<Context> mContext;
   CacheId mCacheId;
   CacheStreamControlParent* mStreamControl;
   nsTArray<Entry> mList;