Bug 1251881 - use UniquePtr instead of ScopedDeletePtr in mozglue/linker/; r=glandium
authorNathan Froyd <froydnj@mozilla.com>
Fri, 26 Feb 2016 13:50:59 -0500
changeset 286644 af6363aa513b304758521d03e3e5286ece7fed23
parent 286643 83058edfb8f2645f5523a01a4140ee268f3a562e
child 286645 40132260efdaddbf68b00a337644a4025a9f4195
push id72858
push usernfroyd@mozilla.com
push dateThu, 03 Mar 2016 18:32:57 +0000
treeherdermozilla-inbound@af6363aa513b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1251881
milestone47.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 1251881 - use UniquePtr instead of ScopedDeletePtr in mozglue/linker/; r=glandium There are two instances: - MappableSeekableZStream::Create uses ScopedDeletePtr, which is actually a little odd, since MappableSeekableZStream, as a Mappable, is refcounted, and it's unusual to use two different kinds of smart pointers for a single class. I think the more natural thing would be for MappableSeekableZStream::Create to return an already_AddRefed, but that change spirals out of the realm of "simple refactoring" quickly. - SzipCompress::run uses ScopedDeletePtr along with some dubious use of raw pointers. I changed things out for UniquePtr and also tidied the memory management a bit, which I think makes things a little clearer.
mozglue/linker/Mappable.cpp
mozglue/linker/szip.cpp
--- a/mozglue/linker/Mappable.cpp
+++ b/mozglue/linker/Mappable.cpp
@@ -373,18 +373,17 @@ MappableDeflate::GetLength() const
   return buffer->GetLength();
 }
 
 Mappable *
 MappableSeekableZStream::Create(const char *name, Zip *zip,
                                 Zip::Stream *stream)
 {
   MOZ_ASSERT(stream->GetType() == Zip::Stream::STORE);
-  mozilla::ScopedDeletePtr<MappableSeekableZStream> mappable;
-  mappable = new MappableSeekableZStream(zip);
+  UniquePtr<MappableSeekableZStream> mappable(new MappableSeekableZStream(zip));
 
   pthread_mutexattr_t recursiveAttr;
   pthread_mutexattr_init(&recursiveAttr);
   pthread_mutexattr_settype(&recursiveAttr, PTHREAD_MUTEX_RECURSIVE);
 
   if (pthread_mutex_init(&mappable->mutex, &recursiveAttr))
     return nullptr;
 
@@ -393,17 +392,17 @@ MappableSeekableZStream::Create(const ch
 
   mappable->buffer.reset(_MappableBuffer::Create(name,
                               mappable->zStream.GetUncompressedSize()));
   if (!mappable->buffer)
     return nullptr;
 
   mappable->chunkAvail = MakeUnique<unsigned char[]>(mappable->zStream.GetChunksNum());
 
-  return mappable.forget();
+  return mappable.release();
 }
 
 MappableSeekableZStream::MappableSeekableZStream(Zip *zip)
 : zip(zip), chunkAvailNum(0) { }
 
 MappableSeekableZStream::~MappableSeekableZStream()
 {
   pthread_mutex_destroy(&mutex);
--- a/mozglue/linker/szip.cpp
+++ b/mozglue/linker/szip.cpp
@@ -267,47 +267,46 @@ int SzipCompress::run(const char *name, 
     lastFilter = SeekableZStream::FILTER_MAX;
     scanFilters = true;
   } else {
     firstFilter = lastFilter = filter;
     ++lastFilter;
     scanFilters = false;
   }
 
-  mozilla::ScopedDeletePtr<Buffer> filteredBuf;
+  mozilla::UniquePtr<Buffer> filteredBuf;
   Buffer *origData;
   for (SeekableZStream::FilterId f = firstFilter; f < lastFilter; ++f) {
-    FilteredBuffer *filteredTmp = nullptr;
+    mozilla::UniquePtr<FilteredBuffer> filteredTmp;
     Buffer tmpBuf;
     if (f != SeekableZStream::NONE) {
       DEBUG_LOG("Applying filter \"%s\"", filterName[f]);
-      filteredTmp = new FilteredBuffer();
+      filteredTmp = mozilla::MakeUnique<FilteredBuffer>();
       filteredTmp->Filter(origBuf, f, chunkSize);
-      origData = filteredTmp;
+      origData = filteredTmp.get();
     } else {
       origData = &origBuf;
     }
     if (dictSize  && !scanFilters) {
-      filteredBuf = filteredTmp;
+      filteredBuf = mozilla::Move(filteredTmp);
       break;
     }
     DEBUG_LOG("Compressing with no dictionary");
     if (do_compress(*origData, tmpBuf, nullptr, 0, f) == 0) {
       if (tmpBuf.GetLength() < outBuf.GetLength()) {
         outBuf.Fill(tmpBuf);
         compressed = true;
         filter = f;
-        filteredBuf = filteredTmp;
+        filteredBuf = mozilla::Move(filteredTmp);
         continue;
       }
     }
-    delete filteredTmp;
   }
 
-  origData = filteredBuf ? filteredBuf : &origBuf;
+  origData = filteredBuf ? filteredBuf.get() : &origBuf;
 
   if (dictSize) {
     Dictionary<uint64_t> dict(*origData, dictSize ? SzipCompress::winSize : 0);
 
     /* Find the most appropriate dictionary size */
     size_t firstDictSize, lastDictSize;
     if (dictSize == (size_t) -1) {
       /* If we scanned for filters, we effectively already tried dictSize=0 */