make SkRefCnt::getRefCnt() debug-only, remove it from SkNVRefCnt.
Only (unused) API removed.
TBR=reed@google.com
BUG=skia:3160
Review URL: https://codereview.chromium.org/752263002
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index d85c20e..7ccfbf9 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -42,8 +42,10 @@
#endif
}
+#ifdef SK_DEBUG
/** Return the reference count. Use only for debugging. */
int32_t getRefCnt() const { return fRefCnt; }
+#endif
/** May return true if the caller is the only owner.
* Ensures that all previous owner's actions are complete.
@@ -269,7 +271,6 @@
}
}
void deref() const { this->unref(); } // Chrome prefers to call deref().
- int32_t getRefCnt() const { return fRefCnt; } // Used by Chrome unit tests.
protected:
#ifdef SK_DEBUG
diff --git a/tests/MetaDataTest.cpp b/tests/MetaDataTest.cpp
index eb7eae9..8ed1e49 100644
--- a/tests/MetaDataTest.cpp
+++ b/tests/MetaDataTest.cpp
@@ -10,7 +10,7 @@
static void test_ptrs(skiatest::Reporter* reporter) {
SkRefCnt ref;
- REPORTER_ASSERT(reporter, 1 == ref.getRefCnt());
+ REPORTER_ASSERT(reporter, ref.unique());
{
SkMetaData md0, md1;
@@ -19,19 +19,19 @@
md0.setRefCnt(name, &ref);
REPORTER_ASSERT(reporter, md0.findRefCnt(name));
REPORTER_ASSERT(reporter, md0.hasRefCnt(name, &ref));
- REPORTER_ASSERT(reporter, 2 == ref.getRefCnt());
+ REPORTER_ASSERT(reporter, !ref.unique());
md1 = md0;
REPORTER_ASSERT(reporter, md1.findRefCnt(name));
REPORTER_ASSERT(reporter, md1.hasRefCnt(name, &ref));
- REPORTER_ASSERT(reporter, 3 == ref.getRefCnt());
+ REPORTER_ASSERT(reporter, !ref.unique());
REPORTER_ASSERT(reporter, md0.removeRefCnt(name));
REPORTER_ASSERT(reporter, !md0.findRefCnt(name));
REPORTER_ASSERT(reporter, !md0.hasRefCnt(name, &ref));
- REPORTER_ASSERT(reporter, 2 == ref.getRefCnt());
+ REPORTER_ASSERT(reporter, !ref.unique());
}
- REPORTER_ASSERT(reporter, 1 == ref.getRefCnt());
+ REPORTER_ASSERT(reporter, ref.unique());
}
DEF_TEST(MetaData, reporter) {
diff --git a/tests/RefCntTest.cpp b/tests/RefCntTest.cpp
index cf6ca3e..cf4acc6 100644
--- a/tests/RefCntTest.cpp
+++ b/tests/RefCntTest.cpp
@@ -49,7 +49,7 @@
thing1.join();
thing2.join();
- REPORTER_ASSERT(reporter, ref->getRefCnt() == 1);
+ REPORTER_ASSERT(reporter, ref->unique());
ref->unref();
}
@@ -93,7 +93,7 @@
thing3.join();
thing4.join();
- REPORTER_ASSERT(reporter, ref->getRefCnt() == 1);
+ REPORTER_ASSERT(reporter, ref->unique());
REPORTER_ASSERT(reporter, ref->getWeakCnt() == 1);
ref->unref();
}
diff --git a/tests/RefDictTest.cpp b/tests/RefDictTest.cpp
index 1e18a68..23e4b11 100644
--- a/tests/RefDictTest.cpp
+++ b/tests/RefDictTest.cpp
@@ -25,50 +25,50 @@
dict.set("foo", &data0);
REPORTER_ASSERT(reporter, &data0 == dict.find("foo"));
- REPORTER_ASSERT(reporter, 2 == data0.getRefCnt());
+ REPORTER_ASSERT(reporter, !data0.unique());
dict.set("foo", &data0);
REPORTER_ASSERT(reporter, &data0 == dict.find("foo"));
- REPORTER_ASSERT(reporter, 2 == data0.getRefCnt());
+ REPORTER_ASSERT(reporter, !data0.unique());
dict.set("foo", &data1);
REPORTER_ASSERT(reporter, &data1 == dict.find("foo"));
- REPORTER_ASSERT(reporter, 1 == data0.getRefCnt());
- REPORTER_ASSERT(reporter, 2 == data1.getRefCnt());
+ REPORTER_ASSERT(reporter, data0.unique());
+ REPORTER_ASSERT(reporter, !data1.unique());
dict.set("foo", NULL);
REPORTER_ASSERT(reporter, NULL == dict.find("foo"));
- REPORTER_ASSERT(reporter, 1 == data0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == data1.getRefCnt());
+ REPORTER_ASSERT(reporter, data0.unique());
+ REPORTER_ASSERT(reporter, data1.unique());
dict.set("foo", &data0);
dict.set("bar", &data1);
REPORTER_ASSERT(reporter, &data0 == dict.find("foo"));
REPORTER_ASSERT(reporter, &data1 == dict.find("bar"));
- REPORTER_ASSERT(reporter, 2 == data0.getRefCnt());
- REPORTER_ASSERT(reporter, 2 == data1.getRefCnt());
+ REPORTER_ASSERT(reporter, !data0.unique());
+ REPORTER_ASSERT(reporter, !data1.unique());
dict.set("foo", &data1);
REPORTER_ASSERT(reporter, &data1 == dict.find("foo"));
REPORTER_ASSERT(reporter, &data1 == dict.find("bar"));
- REPORTER_ASSERT(reporter, 1 == data0.getRefCnt());
- REPORTER_ASSERT(reporter, 3 == data1.getRefCnt());
+ REPORTER_ASSERT(reporter, data0.unique());
+ REPORTER_ASSERT(reporter, !data1.unique());
dict.removeAll();
REPORTER_ASSERT(reporter, NULL == dict.find("foo"));
REPORTER_ASSERT(reporter, NULL == dict.find("bar"));
- REPORTER_ASSERT(reporter, 1 == data0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == data1.getRefCnt());
+ REPORTER_ASSERT(reporter, data0.unique());
+ REPORTER_ASSERT(reporter, data1.unique());
{
SkRefDict d;
REPORTER_ASSERT(reporter, NULL == d.find("foo"));
- REPORTER_ASSERT(reporter, 1 == data0.getRefCnt());
+ REPORTER_ASSERT(reporter, data0.unique());
d.set("foo", &data0);
REPORTER_ASSERT(reporter, &data0 == d.find("foo"));
- REPORTER_ASSERT(reporter, 2 == data0.getRefCnt());
+ REPORTER_ASSERT(reporter, !data0.unique());
// let d go out of scope still with a ref on data0
}
// be sure d's destructor lowered data0's owner count back to 1
- REPORTER_ASSERT(reporter, 1 == data0.getRefCnt());
+ REPORTER_ASSERT(reporter, data0.unique());
}
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 1913fcb..6422669 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -77,11 +77,11 @@
size_t size = info.getSafeSize(rowBytes);
SkData* data = SkData::NewUninitialized(size);
- REPORTER_ASSERT(reporter, 1 == data->getRefCnt());
+ REPORTER_ASSERT(reporter, data->unique());
SkImage* image = SkImage::NewRasterData(info, data, rowBytes);
- REPORTER_ASSERT(reporter, 2 == data->getRefCnt());
+ REPORTER_ASSERT(reporter, !data->unique());
image->unref();
- REPORTER_ASSERT(reporter, 1 == data->getRefCnt());
+ REPORTER_ASSERT(reporter, data->unique());
data->unref();
}
diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp
index 2c84c95..81e6492 100644
--- a/tests/UtilsTest.cpp
+++ b/tests/UtilsTest.cpp
@@ -27,30 +27,30 @@
static void test_autounref(skiatest::Reporter* reporter) {
RefClass obj(0);
- REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
+ REPORTER_ASSERT(reporter, obj.unique());
SkAutoTUnref<RefClass> tmp(&obj);
REPORTER_ASSERT(reporter, &obj == tmp.get());
- REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
+ REPORTER_ASSERT(reporter, obj.unique());
REPORTER_ASSERT(reporter, &obj == tmp.detach());
- REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
+ REPORTER_ASSERT(reporter, obj.unique());
REPORTER_ASSERT(reporter, NULL == tmp.detach());
REPORTER_ASSERT(reporter, NULL == tmp.get());
obj.ref();
- REPORTER_ASSERT(reporter, 2 == obj.getRefCnt());
+ REPORTER_ASSERT(reporter, !obj.unique());
{
SkAutoTUnref<RefClass> tmp2(&obj);
}
- REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
+ REPORTER_ASSERT(reporter, obj.unique());
}
static void test_autostarray(skiatest::Reporter* reporter) {
RefClass obj0(0);
RefClass obj1(1);
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, obj0.unique());
+ REPORTER_ASSERT(reporter, obj1.unique());
{
SkAutoSTArray<2, SkAutoTUnref<RefClass> > tmp;
@@ -61,14 +61,14 @@
REPORTER_ASSERT(reporter, 4 == tmp.count());
tmp[0].reset(SkRef(&obj0));
tmp[1].reset(SkRef(&obj1));
- REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, !obj0.unique());
+ REPORTER_ASSERT(reporter, !obj1.unique());
// test out reset with data in the array (and a new allocation)
tmp.reset(0);
REPORTER_ASSERT(reporter, 0 == tmp.count());
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, obj0.unique());
+ REPORTER_ASSERT(reporter, obj1.unique());
tmp.reset(2); // this should use the preexisting allocation
REPORTER_ASSERT(reporter, 2 == tmp.count());
@@ -77,8 +77,8 @@
}
// test out destructor with data in the array (and using existing allocation)
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, obj0.unique());
+ REPORTER_ASSERT(reporter, obj1.unique());
{
// test out allocating ctor (this should allocate new memory)
@@ -87,32 +87,32 @@
tmp[0].reset(SkRef(&obj0));
tmp[1].reset(SkRef(&obj1));
- REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, !obj0.unique());
+ REPORTER_ASSERT(reporter, !obj1.unique());
// Test out resut with data in the array and malloced storage
tmp.reset(0);
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, obj0.unique());
+ REPORTER_ASSERT(reporter, obj1.unique());
tmp.reset(2); // this should use the preexisting storage
tmp[0].reset(SkRef(&obj0));
tmp[1].reset(SkRef(&obj1));
- REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, !obj0.unique());
+ REPORTER_ASSERT(reporter, !obj1.unique());
tmp.reset(4); // this should force a new malloc
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, obj0.unique());
+ REPORTER_ASSERT(reporter, obj1.unique());
tmp[0].reset(SkRef(&obj0));
tmp[1].reset(SkRef(&obj1));
- REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, !obj0.unique());
+ REPORTER_ASSERT(reporter, !obj1.unique());
}
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, obj0.unique());
+ REPORTER_ASSERT(reporter, obj1.unique());
}
/////////////////////////////////////////////////////////////////////////////