Bug 1410252 - Convert 'WrapNotNull(new T(...' to 'MakeNotNull<T*>(...' - r=njn
authorGerald Squelart <gsquelart@mozilla.com>
Fri, 20 Oct 2017 18:25:33 +1100
changeset 387592 5fbd0369b400b567ff0e4064b02dec16b7572a8c
parent 387591 ec8754342714c155836d8fda18a6d0f175a49d1c
child 387593 1a4d6bea605f35baa8c232f0860bf90e9983759a
push id32729
push userarchaeopteryx@coole-files.de
push dateMon, 23 Oct 2017 09:33:12 +0000
treeherdermozilla-central@b39904cff06b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1410252
milestone58.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 1410252 - Convert 'WrapNotNull(new T(...' to 'MakeNotNull<T*>(...' - r=njn Most cases where the pointer is stored into an already-declared variable can trivially be changed to MakeNotNull<T*>, as the NotNull raw pointer will end up in a smart pointer. In RAII cases, the target type can be specified (e.g.: `MakeNotNull<RefPtr<imgFrame>>)`), in which case the variable type may just be `auto`, similar to the common use of MakeUnique. Except when the target type is a base pointer, in which case it must be specified in the declaration. MozReview-Commit-ID: BYaSsvMhiDi
dom/workers/WorkerThread.cpp
gfx/thebes/gfxFontFamilyList.h
image/Decoder.cpp
image/DecoderFactory.cpp
image/RasterImage.cpp
image/SurfaceCache.cpp
image/VectorImage.cpp
image/test/gtest/Common.cpp
image/test/gtest/TestDecoders.cpp
image/test/gtest/TestMetadata.cpp
tools/profiler/core/ThreadInfo.cpp
widget/android/AndroidUiThread.cpp
--- a/dom/workers/WorkerThread.cpp
+++ b/dom/workers/WorkerThread.cpp
@@ -62,18 +62,18 @@ private:
   {
     mWorkerPrivate->AssertIsOnWorkerThread();
   }
 
   NS_DECL_NSITHREADOBSERVER
 };
 
 WorkerThread::WorkerThread()
-  : nsThread(WrapNotNull(new ThreadEventQueue<mozilla::EventQueue>(
-                           MakeUnique<mozilla::EventQueue>())),
+  : nsThread(MakeNotNull<ThreadEventQueue<mozilla::EventQueue>*>(
+               MakeUnique<mozilla::EventQueue>()),
              nsThread::NOT_MAIN_THREAD,
              kWorkerStackSize)
   , mLock("WorkerThread::mLock")
   , mWorkerPrivateCondVar(mLock, "WorkerThread::mWorkerPrivateCondVar")
   , mWorkerPrivate(nullptr)
   , mOtherThreadsDispatchingViaEventTarget(0)
 #ifdef DEBUG
   , mAcceptingNonWorkerRunnables(true)
--- a/gfx/thebes/gfxFontFamilyList.h
+++ b/gfx/thebes/gfxFontFamilyList.h
@@ -256,36 +256,36 @@ class FontFamilyList {
 public:
     FontFamilyList()
         : mFontlist(WrapNotNull(SharedFontList::sEmpty.get()))
         , mDefaultFontType(eFamily_none)
     {
     }
 
     explicit FontFamilyList(FontFamilyType aGenericType)
-        : mFontlist(WrapNotNull(new SharedFontList(aGenericType)))
+        : mFontlist(MakeNotNull<SharedFontList*>(aGenericType))
         , mDefaultFontType(eFamily_none)
     {
     }
 
     FontFamilyList(const nsAString& aFamilyName,
                    QuotedName aQuoted)
-        : mFontlist(WrapNotNull(new SharedFontList(aFamilyName, aQuoted)))
+        : mFontlist(MakeNotNull<SharedFontList*>(aFamilyName, aQuoted))
         , mDefaultFontType(eFamily_none)
     {
     }
 
     explicit FontFamilyList(const FontFamilyName& aName)
-        : mFontlist(WrapNotNull(new SharedFontList(aName)))
+        : mFontlist(MakeNotNull<SharedFontList*>(aName))
         , mDefaultFontType(eFamily_none)
     {
     }
 
     explicit FontFamilyList(nsTArray<FontFamilyName>&& aNames)
-        : mFontlist(WrapNotNull(new SharedFontList(Move(aNames))))
+        : mFontlist(MakeNotNull<SharedFontList*>(Move(aNames)))
     {
     }
 
     FontFamilyList(const FontFamilyList& aOther)
         : mFontlist(aOther.mFontlist)
         , mDefaultFontType(aOther.mDefaultFontType)
     {
     }
@@ -293,17 +293,17 @@ public:
     explicit FontFamilyList(NotNull<SharedFontList*> aFontList)
         : mFontlist(aFontList)
         , mDefaultFontType(eFamily_none)
     {
     }
 
     void SetFontlist(nsTArray<FontFamilyName>&& aNames)
     {
-        mFontlist = WrapNotNull(new SharedFontList(Move(aNames)));
+        mFontlist = MakeNotNull<SharedFontList*>(Move(aNames));
     }
 
     void SetFontlist(NotNull<SharedFontList*> aFontlist)
     {
         mFontlist = aFontlist;
     }
 
     uint32_t Length() const {
--- a/image/Decoder.cpp
+++ b/image/Decoder.cpp
@@ -327,17 +327,17 @@ Decoder::AllocateFrameInternal(uint32_t 
   }
 
   if (aOutputSize.width <= 0 || aOutputSize.height <= 0 ||
       aFrameRect.Width() <= 0 || aFrameRect.Height() <= 0) {
     NS_WARNING("Trying to add frame with zero or negative size");
     return RawAccessFrameRef();
   }
 
-  NotNull<RefPtr<imgFrame>> frame = WrapNotNull(new imgFrame());
+  auto frame = MakeNotNull<RefPtr<imgFrame>>();
   bool nonPremult = bool(mSurfaceFlags & SurfaceFlags::NO_PREMULTIPLY_ALPHA);
   if (NS_FAILED(frame->InitForDecoder(aOutputSize, aFrameRect, aFormat,
                                       aPaletteDepth, nonPremult,
                                       aFrameNum > 0))) {
     NS_WARNING("imgFrame::Init should succeed");
     return RawAccessFrameRef();
   }
 
--- a/image/DecoderFactory.cpp
+++ b/image/DecoderFactory.cpp
@@ -136,20 +136,18 @@ DecoderFactory::CreateDecoder(DecoderTyp
   if (NS_FAILED(decoder->Init())) {
     return nullptr;
   }
 
   // Create a DecodedSurfaceProvider which will manage the decoding process and
   // make this decoder's output available in the surface cache.
   SurfaceKey surfaceKey =
     RasterSurfaceKey(aOutputSize, aSurfaceFlags, PlaybackType::eStatic);
-  NotNull<RefPtr<DecodedSurfaceProvider>> provider =
-    WrapNotNull(new DecodedSurfaceProvider(aImage,
-                                           surfaceKey,
-                                           WrapNotNull(decoder)));
+  auto provider = MakeNotNull<RefPtr<DecodedSurfaceProvider>>(
+    aImage, surfaceKey, WrapNotNull(decoder));
   if (aDecoderFlags & DecoderFlags::CANNOT_SUBSTITUTE) {
     provider->Availability().SetCannotSubstitute();
   }
 
   // Attempt to insert the surface provider into the surface cache right away so
   // we won't trigger any more decoders with the same parameters.
   if (SurfaceCache::Insert(provider) != InsertOutcome::SUCCESS) {
     return nullptr;
@@ -189,20 +187,18 @@ DecoderFactory::CreateAnimationDecoder(D
   if (NS_FAILED(decoder->Init())) {
     return nullptr;
   }
 
   // Create an AnimationSurfaceProvider which will manage the decoding process
   // and make this decoder's output available in the surface cache.
   SurfaceKey surfaceKey =
     RasterSurfaceKey(aIntrinsicSize, aSurfaceFlags, PlaybackType::eAnimated);
-  NotNull<RefPtr<AnimationSurfaceProvider>> provider =
-    WrapNotNull(new AnimationSurfaceProvider(aImage,
-                                             surfaceKey,
-                                             WrapNotNull(decoder)));
+  auto provider = MakeNotNull<RefPtr<AnimationSurfaceProvider>>(
+    aImage, surfaceKey, WrapNotNull(decoder));
 
   // Attempt to insert the surface provider into the surface cache right away so
   // we won't trigger any more decoders with the same parameters.
   if (SurfaceCache::Insert(provider) != InsertOutcome::SUCCESS) {
     return nullptr;
   }
 
   // Return the surface provider in its IDecodingTask guise.
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -74,17 +74,17 @@ RasterImage::RasterImage(ImageURL* aURI 
   mLockCount(0),
   mDecodeCount(0),
   mImageProducerID(ImageContainer::AllocateProducerID()),
   mLastFrameID(0),
   mLastImageContainerDrawResult(DrawResult::NOT_READY),
 #ifdef DEBUG
   mFramesNotified(0),
 #endif
-  mSourceBuffer(WrapNotNull(new SourceBuffer())),
+  mSourceBuffer(MakeNotNull<SourceBuffer*>()),
   mHasSize(false),
   mTransient(false),
   mSyncLoad(false),
   mDiscardable(false),
   mSomeSourceData(false),
   mAllSourceData(false),
   mHasBeenDecoded(false),
   mPendingAnimation(false),
--- a/image/SurfaceCache.cpp
+++ b/image/SurfaceCache.cpp
@@ -770,18 +770,17 @@ public:
       mImageCaches.Put(aProvider->GetImageKey(), cache);
     }
 
     // If we were asked to mark the cache entry available, do so.
     if (aSetAvailable) {
       aProvider->Availability().SetAvailable();
     }
 
-    NotNull<RefPtr<CachedSurface>> surface =
-      WrapNotNull(new CachedSurface(aProvider));
+    auto surface = MakeNotNull<RefPtr<CachedSurface>>(aProvider);
 
     // We require that locking succeed if the image is locked and we're not
     // inserting a placeholder; the caller may need to know this to handle
     // errors correctly.
     bool mustLock = cache->IsLocked() && !surface->IsPlaceholder();
     if (mustLock) {
       surface->SetLocked(true);
       if (!surface->IsLocked()) {
--- a/image/VectorImage.cpp
+++ b/image/VectorImage.cpp
@@ -964,17 +964,17 @@ VectorImage::CreateSurfaceAndShow(const 
   // expire from the cache by unlocking them here, and then sending out an
   // invalidation. If this image is locked, any surfaces that are still useful
   // will become locked again when Draw touches them, and the remainder will
   // eventually expire.
   SurfaceCache::UnlockEntries(ImageKey(this));
 
   // Try to create an imgFrame, initializing the surface it contains by drawing
   // our gfxDrawable into it. (We use FILTER_NEAREST since we never scale here.)
-  NotNull<RefPtr<imgFrame>> frame = WrapNotNull(new imgFrame);
+  auto frame = MakeNotNull<RefPtr<imgFrame>>();
   nsresult rv =
     frame->InitWithDrawable(svgDrawable, aParams.size,
                             SurfaceFormat::B8G8R8A8,
                             SamplingFilter::POINT, aParams.flags,
                             aBackend);
 
   // If we couldn't create the frame, it was probably because it would end
   // up way too big. Generally it also wouldn't fit in the cache, but the prefs
@@ -988,17 +988,17 @@ VectorImage::CreateSurfaceAndShow(const 
   RefPtr<SourceSurface> surface = frame->GetSourceSurface();
   if (!surface) {
     return Show(svgDrawable, aParams);
   }
 
   // Attempt to cache the frame.
   SurfaceKey surfaceKey = VectorSurfaceKey(aParams.size, aParams.svgContext);
   NotNull<RefPtr<ISurfaceProvider>> provider =
-    WrapNotNull(new SimpleSurfaceProvider(ImageKey(this), surfaceKey, frame));
+    MakeNotNull<SimpleSurfaceProvider*>(ImageKey(this), surfaceKey, frame);
   SurfaceCache::Insert(provider);
 
   // Draw.
   RefPtr<gfxDrawable> drawable =
     new gfxSurfaceDrawable(surface, aParams.size);
   Show(drawable, aParams);
 
   // Send out an invalidation so that surfaces that are still in use get
--- a/image/test/gtest/Common.cpp
+++ b/image/test/gtest/Common.cpp
@@ -294,17 +294,17 @@ RowHasPixels(SourceSurface* aSurface,
 // SurfacePipe Helpers
 ///////////////////////////////////////////////////////////////////////////////
 
 already_AddRefed<Decoder>
 CreateTrivialDecoder()
 {
   gfxPrefs::GetSingleton();
   DecoderType decoderType = DecoderFactory::GetDecoderType("image/gif");
-  NotNull<RefPtr<SourceBuffer>> sourceBuffer = WrapNotNull(new SourceBuffer());
+  auto sourceBuffer = MakeNotNull<RefPtr<SourceBuffer>>();
   RefPtr<Decoder> decoder =
     DecoderFactory::CreateAnonymousDecoder(decoderType, sourceBuffer, Nothing(),
                                            DefaultSurfaceFlags());
   return decoder.forget();
 }
 
 void
 AssertCorrectPipelineFinalState(SurfaceFilter* aFilter,
--- a/image/test/gtest/TestDecoders.cpp
+++ b/image/test/gtest/TestDecoders.cpp
@@ -98,17 +98,17 @@ void WithSingleChunkDecode(const ImageTe
   ASSERT_TRUE(inputStream != nullptr);
 
   // Figure out how much data we have.
   uint64_t length;
   nsresult rv = inputStream->Available(&length);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   // Write the data into a SourceBuffer.
-  NotNull<RefPtr<SourceBuffer>> sourceBuffer = WrapNotNull(new SourceBuffer());
+  auto sourceBuffer = MakeNotNull<RefPtr<SourceBuffer>>();
   sourceBuffer->ExpectLength(length);
   rv = sourceBuffer->AppendFromInputStream(inputStream, length);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
   sourceBuffer->Complete(NS_OK);
 
   // Create a decoder.
   DecoderType decoderType =
     DecoderFactory::GetDecoderType(aTestCase.mMimeType);
@@ -140,17 +140,17 @@ CheckDecoderMultiChunk(const ImageTestCa
   ASSERT_TRUE(inputStream != nullptr);
 
   // Figure out how much data we have.
   uint64_t length;
   nsresult rv = inputStream->Available(&length);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   // Create a SourceBuffer and a decoder.
-  NotNull<RefPtr<SourceBuffer>> sourceBuffer = WrapNotNull(new SourceBuffer());
+  auto sourceBuffer = MakeNotNull<RefPtr<SourceBuffer>>();
   sourceBuffer->ExpectLength(length);
   DecoderType decoderType =
     DecoderFactory::GetDecoderType(aTestCase.mMimeType);
   RefPtr<Decoder> decoder =
     DecoderFactory::CreateAnonymousDecoder(decoderType, sourceBuffer, Nothing(),
                                            DefaultSurfaceFlags());
   ASSERT_TRUE(decoder != nullptr);
   RefPtr<IDecodingTask> task = new AnonymousDecodingTask(WrapNotNull(decoder));
--- a/image/test/gtest/TestMetadata.cpp
+++ b/image/test/gtest/TestMetadata.cpp
@@ -43,17 +43,17 @@ CheckMetadata(const ImageTestCase& aTest
   ASSERT_TRUE(inputStream != nullptr);
 
   // Figure out how much data we have.
   uint64_t length;
   nsresult rv = inputStream->Available(&length);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   // Write the data into a SourceBuffer.
-  NotNull<RefPtr<SourceBuffer>> sourceBuffer = WrapNotNull(new SourceBuffer());
+  auto sourceBuffer = MakeNotNull<RefPtr<SourceBuffer>>();
   sourceBuffer->ExpectLength(length);
   rv = sourceBuffer->AppendFromInputStream(inputStream, length);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
   sourceBuffer->Complete(NS_OK);
 
   // Create a metadata decoder.
   DecoderType decoderType =
     DecoderFactory::GetDecoderType(aTestCase.mMimeType);
--- a/tools/profiler/core/ThreadInfo.cpp
+++ b/tools/profiler/core/ThreadInfo.cpp
@@ -14,23 +14,25 @@
 
 #ifdef XP_WIN
 #include <process.h>
 #define getpid _getpid
 #else
 #include <unistd.h> // for getpid()
 #endif
 
-ThreadInfo::ThreadInfo(const char* aName, int aThreadId, bool aIsMainThread,
+ThreadInfo::ThreadInfo(const char* aName,
+                       int aThreadId,
+                       bool aIsMainThread,
                        void* aStackTop)
   : mName(strdup(aName))
   , mRegisterTime(TimeStamp::Now())
   , mThreadId(aThreadId)
   , mIsMainThread(aIsMainThread)
-  , mRacyInfo(mozilla::WrapNotNull(new RacyThreadInfo()))
+  , mRacyInfo(mozilla::MakeNotNull<RacyThreadInfo*>())
   , mPlatformData(AllocPlatformData(aThreadId))
   , mStackTop(aStackTop)
   , mIsBeingProfiled(false)
   , mContext(nullptr)
   , mJSSampling(INACTIVE)
   , mLastSample()
 {
   MOZ_COUNT_CTOR(ThreadInfo);
--- a/widget/android/AndroidUiThread.cpp
+++ b/widget/android/AndroidUiThread.cpp
@@ -49,18 +49,20 @@ void EnqueueTask(already_AddRefed<nsIRun
  * needs to be drained.
 */
 
 class AndroidUiThread : public nsThread
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   AndroidUiThread()
-    : nsThread(WrapNotNull(new ThreadEventQueue<mozilla::EventQueue>(MakeUnique<mozilla::EventQueue>())),
-               nsThread::NOT_MAIN_THREAD, 0)
+    : nsThread(MakeNotNull<ThreadEventQueue<mozilla::EventQueue>*>(
+                 MakeUnique<mozilla::EventQueue>()),
+               nsThread::NOT_MAIN_THREAD,
+               0)
   {}
 
   nsresult Dispatch(already_AddRefed<nsIRunnable> aEvent, uint32_t aFlags) override;
   nsresult DelayedDispatch(already_AddRefed<nsIRunnable> aEvent, uint32_t aDelayMs) override;
 
 private:
   ~AndroidUiThread()
   {}