Bug 1397128 P2 Refactor StreamList::Add() to use move constructors and accept a nullptr stream. r=tt

This commit is contained in:
Ben Kelly 2017-09-15 12:25:40 -07:00
Родитель 66eb21a04b
Коммит 9bbbfca014
3 изменённых файлов: 12 добавлений и 10 удалений

8
dom/cache/Manager.cpp поставляемый
Просмотреть файл

@ -548,7 +548,7 @@ public:
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; } if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; }
mStreamList->Add(mResponse.mBodyId, stream); mStreamList->Add(mResponse.mBodyId, Move(stream));
return rv; return rv;
} }
@ -614,7 +614,7 @@ public:
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; } 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; return rv;
@ -1162,7 +1162,7 @@ public:
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; } 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; return rv;
@ -1226,7 +1226,7 @@ public:
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; } if (NS_WARN_IF(!stream)) { return NS_ERROR_FILE_NOT_FOUND; }
mStreamList->Add(mSavedResponse.mBodyId, stream); mStreamList->Add(mSavedResponse.mBodyId, Move(stream));
return rv; return rv;
} }

7
dom/cache/StreamList.cpp поставляемый
Просмотреть файл

@ -70,15 +70,12 @@ StreamList::Activate(CacheId aCacheId)
} }
void 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 // All streams should be added on IO thread before we set the stream
// control on the owning IPC thread. // control on the owning IPC thread.
MOZ_DIAGNOSTIC_ASSERT(!mStreamControl); MOZ_DIAGNOSTIC_ASSERT(!mStreamControl);
MOZ_DIAGNOSTIC_ASSERT(aStream); mList.AppendElement(Entry(aId, Move(aStream)));
Entry* entry = mList.AppendElement();
entry->mId = aId;
entry->mStream = aStream;
} }
already_AddRefed<nsIInputStream> already_AddRefed<nsIInputStream>

7
dom/cache/StreamList.h поставляемый
Просмотреть файл

@ -31,7 +31,7 @@ public:
void Activate(CacheId aCacheId); 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); already_AddRefed<nsIInputStream> Extract(const nsID& aId);
void NoteClosed(const nsID& aId); void NoteClosed(const nsID& aId);
@ -47,6 +47,11 @@ private:
~StreamList(); ~StreamList();
struct Entry struct Entry
{ {
explicit Entry(const nsID& aId, nsCOMPtr<nsIInputStream>&& aStream)
: mId(aId)
, mStream(Move(aStream))
{}
nsID mId; nsID mId;
nsCOMPtr<nsIInputStream> mStream; nsCOMPtr<nsIInputStream> mStream;
}; };