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/samplecode/SampleFontScalerTest.cpp b/samplecode/SampleFontScalerTest.cpp
index d597a9a..de70292 100644
--- a/samplecode/SampleFontScalerTest.cpp
+++ b/samplecode/SampleFontScalerTest.cpp
@@ -39,10 +39,10 @@
                                                    gFaces[i].fStyle);
         }
     }
-    
+
     virtual ~FontScalerTestView() {
         for (int i = 0; i < gFaceCount; i++) {
-            fFaces[i]->safeUnref();
+            SkSafeUnref(fFaces[i]);
         }
     }
 
@@ -55,14 +55,14 @@
         }
         return this->INHERITED::onQuery(evt);
     }
-    
+
     void drawBG(SkCanvas* canvas) {
         canvas->drawColor(0xFFDDDDDD);
     }
-    
+
     virtual void onDraw(SkCanvas* canvas) {
         this->drawBG(canvas);
-        
+
         SkPaint paint;
 
         // test handling of obscene cubic values (currently broken)
@@ -72,19 +72,19 @@
             pts[1].set(-7.18397061e+15, -1.53091184e+13);
             pts[2].set(-1.30077315e+16, -2.77196141e+13);
             pts[3].set(-1.30077315e+16, -2.77196162e+13);
-            
+
             SkPath path;
             path.moveTo(pts[0]);
             path.cubicTo(pts[1], pts[2], pts[3]);
             canvas->drawPath(path, paint);
         }
-        
+
         canvas->translate(200, 20);
         canvas->rotate(30);
 
         paint.setAntiAlias(true);
-        paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal))->safeUnref();
-        
+        SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal)));
+
 //        const char* text = "abcdefghijklmnopqrstuvwxyz";
         const char* text = "HnHnHnHnHnHnHnHnH";
         size_t textLen = strlen(text);
@@ -99,7 +99,7 @@
             r.set(0, 0, x, y*20);
             canvas->drawRect(r, p);
         }
-        
+
         int index = 0;
         for (int ps = 9; ps <= 24; ps++) {
             textLen = strlen(text);
@@ -109,7 +109,7 @@
             index += 1;
         }
     }
-    
+
 private:
     typedef SkView INHERITED;
 };