Bug 695962. imglib: Remove a bunch of null checks after new. r=bholley
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Wed, 19 Oct 2011 23:21:56 -0400
changeset 80856 aacc24a428856b1b0e8723703fcf70ecf612ac0e
parent 80855 7aa60d6408b303b68ea58cea1266cc556fc6de9d
child 80857 08a63bc26c755fa740ab19c9d12b4b603a1e1508
push id90
push userffxbld
push dateSun, 29 Jan 2012 07:46:52 +0000
treeherdermozilla-release@acddb6b6a01c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs695962
milestone10.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 695962. imglib: Remove a bunch of null checks after new. r=bholley
image/src/RasterImage.cpp
image/src/imgFrame.cpp
image/src/imgLoader.cpp
image/src/imgTools.cpp
--- a/image/src/RasterImage.cpp
+++ b/image/src/RasterImage.cpp
@@ -334,17 +334,16 @@ RasterImage::ExtractFrame(PRUint32 aWhic
     return NS_ERROR_FAILURE;
 
   // Disallowed in the API
   if (mInDecoder && (aFlags & imgIContainer::FLAG_SYNC_DECODE))
     return NS_ERROR_FAILURE;
 
   // Make a new container. This should switch to another class with bug 505959.
   nsRefPtr<RasterImage> img(new RasterImage());
-  NS_ENSURE_TRUE(img, NS_ERROR_OUT_OF_MEMORY);
 
   // We don't actually have a mimetype in this case. The empty string tells the
   // init routine not to try to instantiate a decoder. This should be fixed in
   // bug 505959.
   img->Init(nsnull, "", "", INIT_FLAG_NONE);
   img->SetSize(aRegion.width, aRegion.height);
   img->mDecoded = true; // Also, we need to mark the image as decoded
   img->mHasBeenDecoded = true;
@@ -844,17 +843,16 @@ RasterImage::InternalAddFrame(PRUint32 f
   // lock frames.
   NS_ABORT_IF_FALSE(mInDecoder, "Only decoders may add frames!");
 
   NS_ABORT_IF_FALSE(framenum <= mFrames.Length(), "Invalid frame index!");
   if (framenum > mFrames.Length())
     return NS_ERROR_INVALID_ARG;
 
   nsAutoPtr<imgFrame> frame(new imgFrame());
-  NS_ENSURE_TRUE(frame, NS_ERROR_OUT_OF_MEMORY);
 
   nsresult rv = frame->Init(aX, aY, aWidth, aHeight, aFormat, aPaletteDepth);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // We know we are in a decoder. Therefore, we must unlock the previous frame
   // when we move on to decoding into the next frame.
   if (mFrames.Length() > 0) {
     imgFrame *prevframe = mFrames.ElementAt(mFrames.Length() - 1);
@@ -1645,20 +1643,16 @@ RasterImage::DoComposite(nsIntRect* aDir
     return NS_OK;
   }
 
   bool needToBlankComposite = false;
 
   // Create the Compositing Frame
   if (!mAnim->compositingFrame) {
     mAnim->compositingFrame = new imgFrame();
-    if (!mAnim->compositingFrame) {
-      NS_WARNING("Failed to init compositingFrame!\n");
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
     nsresult rv = mAnim->compositingFrame->Init(0, 0, mSize.width, mSize.height,
                                                 gfxASurface::ImageFormatARGB32);
     if (NS_FAILED(rv)) {
       mAnim->compositingFrame = nsnull;
       return rv;
     }
     needToBlankComposite = true;
   } else if (aNextFrameIndex != mAnim->lastCompositedFrameIndex+1) {
@@ -1760,20 +1754,16 @@ RasterImage::DoComposite(nsIntRect* aDir
   // too
   if ((nextFrameDisposalMethod == kDisposeRestorePrevious) &&
       (prevFrameDisposalMethod != kDisposeRestorePrevious)) {
     // We are storing the whole image.
     // It would be better if we just stored the area that nextFrame is going to
     // overwrite.
     if (!mAnim->compositingPrevFrame) {
       mAnim->compositingPrevFrame = new imgFrame();
-      if (!mAnim->compositingPrevFrame) {
-        NS_WARNING("Failed to init compositingPrevFrame!\n");
-        return NS_ERROR_OUT_OF_MEMORY;
-      }
       nsresult rv = mAnim->compositingPrevFrame->Init(0, 0, mSize.width, mSize.height,
                                                       gfxASurface::ImageFormatARGB32);
       if (NS_FAILED(rv)) {
         mAnim->compositingPrevFrame = nsnull;
         return rv;
       }
     }
 
@@ -2348,18 +2338,16 @@ RasterImage::RequestDecode()
   // If our callstack goes through a size decoder, we have a problem.
   // We need to shutdown the size decode and replace it with  a full
   // decoder, but can't do that from within the decoder itself. Thus, we post
   // an asynchronous event to the event loop to do it later. Since
   // RequestDecode() is an asynchronous function this works fine (though it's
   // a little slower).
   if (mInDecoder) {
     nsRefPtr<imgDecodeRequestor> requestor = new imgDecodeRequestor(this);
-    if (!requestor)
-      return NS_ERROR_OUT_OF_MEMORY;
     return NS_DispatchToCurrentThread(requestor);
   }
 
 
   // If we have a size decode open, interrupt it and shut it down; or if
   // the decoder has different flags than what we need
   if (mDecoder &&
       (mDecoder->IsSizeDecode() || mDecoder->GetDecodeFlags() != mFrameDecodeFlags))
--- a/image/src/imgFrame.cpp
+++ b/image/src/imgFrame.cpp
@@ -469,18 +469,16 @@ void imgFrame::Draw(gfxContext *aContext
                                subimage, sourceRect, imageRect, fill,
                                surfaceResult.mFormat, aFilter);
   }
 }
 
 nsresult imgFrame::Extract(const nsIntRect& aRegion, imgFrame** aResult)
 {
   nsAutoPtr<imgFrame> subImage(new imgFrame());
-  if (!subImage)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   // The scaling problems described in bug 468496 are especially
   // likely to be visible for the sub-image, as at present the only
   // user is the border-image code and border-images tend to get
   // stretched a lot.  At the same time, the performance concerns
   // that prevent us from just using Cairo's fallback scaler when
   // accelerated graphics won't cut it are less relevant to such
   // images, since they also tend to be small.  Thus, we forcibly
--- a/image/src/imgLoader.cpp
+++ b/image/src/imgLoader.cpp
@@ -730,17 +730,16 @@ nsresult imgLoader::CreateNewProxyForReq
      proxy calls to |aObserver|.
    */
 
   imgRequestProxy *proxyRequest;
   if (aProxyRequest) {
     proxyRequest = static_cast<imgRequestProxy *>(aProxyRequest);
   } else {
     proxyRequest = new imgRequestProxy();
-    if (!proxyRequest) return NS_ERROR_OUT_OF_MEMORY;
   }
   NS_ADDREF(proxyRequest);
 
   /* It is important to call |SetLoadFlags()| before calling |Init()| because
      |Init()| adds the request to the loadgroup.
    */
   proxyRequest->SetLoadFlags(aLoadFlags);
 
@@ -888,27 +887,23 @@ nsresult imgLoader::InitCache()
   NS_TIME_FUNCTION;
 
   nsresult rv;
   nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
   if (!os)
     return NS_ERROR_FAILURE;
   
   gCacheObserver = new imgCacheObserver();
-  if (!gCacheObserver) 
-    return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(gCacheObserver);
 
   os->AddObserver(gCacheObserver, "memory-pressure", false);
   os->AddObserver(gCacheObserver, "chrome-flush-skin-caches", false);
   os->AddObserver(gCacheObserver, "chrome-flush-caches", false);
 
   gCacheTracker = new imgCacheExpirationTracker();
-  if (!gCacheTracker)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   if (!sCache.Init())
       return NS_ERROR_OUT_OF_MEMORY;
   if (!sChromeCache.Init())
       return NS_ERROR_OUT_OF_MEMORY;
 
   PRInt32 timeweight;
   rv = Preferences::GetInt("image.cache.timeweight", &timeweight);
--- a/image/src/imgTools.cpp
+++ b/image/src/imgTools.cpp
@@ -192,19 +192,16 @@ NS_IMETHODIMP imgTools::EncodeScaledImag
     bitmapDataLength = aScaledHeight * strideSize;
 
   } else {
     // Prepare to draw a scaled version of the image to a temporary surface...
 
     // Create a temporary image surface
     dest = new gfxImageSurface(gfxIntSize(aScaledWidth, aScaledHeight),
                                gfxASurface::ImageFormatARGB32);
-    if (!dest)
-      return NS_ERROR_OUT_OF_MEMORY;
-
     gfxContext ctx(dest);
 
     // Set scaling
     gfxFloat sw = (double) aScaledWidth / w;
     gfxFloat sh = (double) aScaledHeight / h;
     ctx.Scale(sw, sh);
 
     // Paint a scaled image