remove SkRefCnt safeRef() and safeUnref(), and replace the call-sites with
SkSafeRef() and SkSafeUnref().

This is basically a bug waiting to happen. An optimizing compiler can remove
checks for null on "this" if it chooses. However, SkRefCnt::safeRef() relies on
precisely this check...

void SkRefCnt::safeRef() {
    if (this) {
        this->ref();
    }
}

Since a compiler might skip the if-clause, it breaks the intention of this
method, hence its removal.

static inline void SkSafeRef(SkRefCnt* obj) {
    if (obj) {
        obj->ref();
    }
}

This form is not ignored by an optimizing compile, so we use it instead.




git-svn-id: http://skia.googlecode.com/svn/trunk@762 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp
index 4ff7a50..223a4f7 100644
--- a/src/utils/SkDumpCanvas.cpp
+++ b/src/utils/SkDumpCanvas.cpp
@@ -1,5 +1,5 @@
 #include "SkDumpCanvas.h"
-#include "SkPicture.h"  
+#include "SkPicture.h"
 #include "SkPixelRef.h"
 #include "SkString.h"
 #include <stdarg.h>
@@ -105,7 +105,7 @@
 static void toString(const SkBitmap& bm, SkString* str) {
     str->printf("bitmap:[%d %d] %s", bm.width(), bm.height(),
                 toString(bm.config()));
-    
+
     SkPixelRef* pr = bm.pixelRef();
     if (NULL == pr) {
         // show null or the explicit pixel address (rare)
@@ -140,7 +140,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 SkDumpCanvas::SkDumpCanvas(Dumper* dumper) : fNestLevel(0) {
-    dumper->safeRef();
+    SkSafeRef(dumper);
     fDumper = dumper;
 
     static const int WIDE_OPEN = 16384;
@@ -151,7 +151,7 @@
 }
 
 SkDumpCanvas::~SkDumpCanvas() {
-    fDumper->safeUnref();
+    SkSafeUnref(fDumper);
 }
 
 void SkDumpCanvas::dump(Verb verb, const SkPaint* paint,
@@ -163,7 +163,7 @@
     va_start(args, format);
     vsnprintf(buffer, BUFFER_SIZE, format, args);
     va_end(args);
-    
+
     if (fDumper) {
         fDumper->dump(this, verb, buffer, paint);
     }
@@ -420,7 +420,7 @@
         tab.append("\t");
     }
     msg.printf("%s%s", tab.c_str(), str);
-    
+
     if (p) {
         msg.appendf(" color:0x%08X flags:%X", p->getColor(), p->getFlags());
         appendFlattenable(&msg, p->getShader(), "shader");
@@ -429,13 +429,13 @@
         appendFlattenable(&msg, p->getMaskFilter(), "maskFilter");
         appendFlattenable(&msg, p->getPathEffect(), "pathEffect");
         appendFlattenable(&msg, p->getColorFilter(), "filter");
-        
+
         if (SkDumpCanvas::kDrawText_Verb == verb) {
             msg.appendf(" textSize:%g", SkScalarToFloat(p->getTextSize()));
             appendPtr(&msg, p->getTypeface(), "typeface");
         }
     }
-    
+
     fProc(msg.c_str(), fRefcon);
 }