Bug 1249389 - part 2 - change NewBufferFromStorageStream's outparam into a UniquePtr; r=erahm

Similar to the previous change to NewObjectInputStreamFromBuffer, we
want to make the ownership transfer out of NewBufferFromStorageStream
more obvious.  Doing this also lets us get rid of some uses of
nsAutoArrayPtr, which is less idiomatic than UniquePtr.
This commit is contained in:
Nathan Froyd 2016-02-18 12:04:40 -05:00
Родитель cd3c15f774
Коммит f49b2c8d86
5 изменённых файлов: 17 добавлений и 18 удалений

Просмотреть файл

@ -290,11 +290,11 @@ nsXBLDocumentInfo::WritePrototypeBindings()
NS_ENSURE_SUCCESS(rv, rv);
uint32_t len;
nsAutoArrayPtr<char> buf;
rv = NewBufferFromStorageStream(storageStream, getter_Transfers(buf), &len);
UniquePtr<char[]> buf;
rv = NewBufferFromStorageStream(storageStream, &buf, &len);
NS_ENSURE_SUCCESS(rv, rv);
return startupCache->PutBuffer(spec.get(), buf, len);
return startupCache->PutBuffer(spec.get(), buf.get(), len);
}
void

Просмотреть файл

@ -401,10 +401,9 @@ nsXULPrototypeCache::FinishOutputStream(nsIURI* uri)
= do_QueryInterface(storageStream);
outputStream->Close();
nsAutoArrayPtr<char> buf;
UniquePtr<char[]> buf;
uint32_t len;
rv = NewBufferFromStorageStream(storageStream, getter_Transfers(buf),
&len);
rv = NewBufferFromStorageStream(storageStream, &buf, &len);
NS_ENSURE_SUCCESS(rv, rv);
if (!mStartupCacheURITable.GetEntry(uri)) {
@ -412,7 +411,7 @@ nsXULPrototypeCache::FinishOutputStream(nsIURI* uri)
rv = PathifyURI(uri, spec);
if (NS_FAILED(rv))
return NS_ERROR_NOT_AVAILABLE;
rv = sc->PutBuffer(spec.get(), buf, len);
rv = sc->PutBuffer(spec.get(), buf.get(), len);
if (NS_SUCCEEDED(rv)) {
mOutputStreamTable.Remove(uri);
mStartupCacheURITable.PutEntry(uri);

Просмотреть файл

@ -73,7 +73,7 @@ NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
NS_EXPORT nsresult
NewBufferFromStorageStream(nsIStorageStream *storageStream,
char** buffer, uint32_t* len)
UniquePtr<char[]>* buffer, uint32_t* len)
{
nsresult rv;
nsCOMPtr<nsIInputStream> inputStream;
@ -86,9 +86,9 @@ NewBufferFromStorageStream(nsIStorageStream *storageStream,
NS_ENSURE_TRUE(avail64 <= UINT32_MAX, NS_ERROR_FILE_TOO_BIG);
uint32_t avail = (uint32_t)avail64;
nsAutoArrayPtr<char> temp (new char[avail]);
auto temp = MakeUnique<char[]>(avail);
uint32_t read;
rv = inputStream->Read(temp, avail, &read);
rv = inputStream->Read(temp.get(), avail, &read);
if (NS_SUCCEEDED(rv) && avail != read)
rv = NS_ERROR_UNEXPECTED;
@ -97,7 +97,7 @@ NewBufferFromStorageStream(nsIStorageStream *storageStream,
}
*len = avail;
*buffer = temp.forget();
*buffer = Move(temp);
return NS_OK;
}

Просмотреть файл

@ -29,11 +29,11 @@ NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
bool wantDebugStream);
// Creates a buffer for storing the stream into the cache. The buffer is
// allocated with 'new []'. Typically, the caller would store the buffer in
// an nsAutoArrayPtr<char> and then call nsIStartupCache::PutBuffer with it.
// allocated with 'new []'. After calling this function, the caller would
// typically call nsIStartupCache::PutBuffer with the returned buffer.
NS_EXPORT nsresult
NewBufferFromStorageStream(nsIStorageStream *storageStream,
char** buffer, uint32_t* len);
UniquePtr<char[]>* buffer, uint32_t* len);
NS_EXPORT nsresult
PathifyURI(nsIURI *in, nsACString &out);

Просмотреть файл

@ -42,7 +42,7 @@ NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
NS_IMPORT nsresult
NewBufferFromStorageStream(nsIStorageStream *storageStream,
char** buffer, uint32_t* len);
UniquePtr<char[]>* buffer, uint32_t* len);
} // namespace scache
} // namespace mozilla
@ -197,13 +197,13 @@ TestWriteObject() {
return rv;
}
nsAutoArrayPtr<char> buf;
UniquePtr<char[]> buf;
uint32_t len;
NewBufferFromStorageStream(storageStream, getter_Transfers(buf), &len);
NewBufferFromStorageStream(storageStream, &buf, &len);
// Since this is a post-startup write, it should be written and
// available.
rv = sc->PutBuffer(id, buf, len);
rv = sc->PutBuffer(id, buf.get(), len);
if (NS_FAILED(rv)) {
fail("failed to insert input stream");
return rv;